Knowledge Spaces and RAG
Last verified against: commit 6f2f20b (v1.0)
Estimated Read Time: 5 min
Status: built
Knowledge Spaces partition documents, database tables, and ingested content into logical domain boundaries. Assistants bind to one or more spaces to determine their retrieval scope.
1. What a Space Really Is
In Locus, a Knowledge Space is an authorization access group, not a separate physical vector index.
- All chunks across an organization reside in a shared, multi-tenant vector and lexical store.
- Cross-space leakage is prevented at query execution time:
# backend/retrieval/pipeline.py allowed_sources = scope.resolve_allowed_source_ids(db) source_ids = [s for s in source_ids if s in allowed_sources]
- When an assistant executes a retrieval query, the engine fetches the list of source IDs linked via
space_sourcesfor the assistant's spaces. Candidates outside those source IDs are rejected before ranking.
2. Assistant Space Binding
An assistant can bind to multiple spaces. For example:
- A
Customer Supportassistant binds to thePublic DocsandRelease Notesspaces. - An
Internal Opsassistant binds toPublic Docs,Internal Policies, andEmployee Handbook.
When a query is issued to POST /v1/chat, Locus queries assistant_spaces for the active assistant and attaches the resulting space_ids to the execution Scope.
3. The Query Router
When an assistant is configured with strategy: auto, Locus evaluates an upstream deterministic router before executing retrieval:
User Query
|
v
Deterministic Router
|
+--> Structured Route (Exact metric formulas, zero LLM, deterministic SQL aggregation)
|
+--> Semantic Route (Hybrid dense vector + BM25 lexical retrieval + Cross-encoder reranker)
If a user query matches registered semantic table metrics (e.g. "What was our total revenue last month?"), the query router directs execution down the structured computed route, eliminating embedding and LLM latency while avoiding hallucination.
If the question is unstructured or exploratory, the router invokes the hybrid retrieval pipeline.
4. Retrieval Pipeline Parameters
Each assistant allows customizing its retrieval parameters:
| Parameter | Default Value | Description |
|---|---|---|
retrieval_k | 5 | Number of top context chunks injected into the answer prompt. |
min_score | 0.3 | Minimum similarity threshold; candidates below this threshold are discarded. |
strategy | hybrid | Retrieval mode (dense, lexical, hybrid, hybrid_rerank, or auto). |
5. Querying with Custom Strategy
You can test retrieval behavior using a cURL command directed at an assistant:
# Run in terminal curl -X POST http://127.0.0.1:8000/v1/chat \ -H "Content-Type: application/json" \ -H "Authorization: Bearer locus_sk_REPLACE_ME" \ -d '{ "assistant_slug": "knowledge-bot", "message": "List our data retention periods." }'