Knowledge Retrieval
Once documents are indexed, agents retrieve the most relevant passages during task execution — retrieval-augmented generation (RAG). This page covers how retrieval is triggered and how to tune it.
How Retrieval Works
- Understand — Xagent analyses the request.
- Search — it queries the relevant knowledge bases.
- Retrieve — matching passages are extracted with their sources.
- Ground — the model answers using the retrieved context, citing sources where available.
In Tasks & Agents
In a regular task, just describe what you want in natural language — for example, “Search the product documentation for how to reset the device.” Xagent searches automatically when a request references documents, policies, or looking something up.
For an agent, attach one or more knowledge bases in its configuration. The agent then searches only those knowledge bases — ideal for domain-specific assistants (a support agent scoped to product docs, an HR assistant scoped to the employee handbook).
Search Types
| Type | Best for |
|---|---|
| Hybrid (default) | Combines vector and keyword search — the best balance for most queries. |
| Dense | Pure vector similarity — strong for conceptual, semantic queries. |
| Sparse | Pure keyword matching — strong for exact terms, names, and phrases. |
Search Parameters
- Top K (default 5) — maximum results per knowledge base. Higher returns more but is slower.
- Min score (default 0.3) — relevance threshold from 0.0–1.0. Higher filters more aggressively.
Interpret relevance scores roughly as: 0.7+ directly on point, 0.4–0.7 related context, 0.3–0.4 loosely related background.
Better results
Be specific and use domain language in queries. Attach only the knowledge bases an agent actually needs — too many slows retrieval and dilutes relevance. Keep content current by removing stale documents.
Troubleshooting
Agent not using its knowledge base? Check that:
- The knowledge base is attached in the agent's configuration.
- The agent has the
knowledgetool category enabled. - The documents finished indexing (status completed, not pending or failed).
- Your query matches the knowledge base's domain — test with a question you know the documents answer.
No or irrelevant results? Lower the min-score threshold, try more specific domain terminology, or adjust chunking and re-upload (see Uploading Knowledge).