When a knowledge base is attached to an agent, the framework calls it automatically as part of the agent’s reasoning loop and you don’t see the search call. Sometimes you want to search directly: building a search box, enriching a record before it goes into a workflow, or testing how a query ranks against your corpus. That’s whatDocumentation Index
Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
Use this file to discover all available pages before exploring further.
kb.search and agent.knowledge_bases_retriever() are for.
Knowledge base retrieval is wired in automatically only for Agno. For LangChain, OpenAI Agents SDK, and AWS Strands, you need to add the retriever as a tool manually. See the framework pages for details.
Prerequisites
- Complete the Quickstart so the CLI, SDK, and
xpander loginare already set up. - At least one knowledge base created and populated via the Workbench or the Document Management SDK.
1. Search a knowledge base
| Field | What it’s for |
|---|---|
content | The matched chunk of text, not the full document. |
score | Relevance score, higher is better. |
document_name | Name of the source document. |
document_id | Stable ID of the source document. |
2. Tune the query
Two parameters you control:-
top_kcontrols how many results are returned. It defaults to 10. Lower it for tightly scoped queries where you only want the best match; raise it when feeding results into a downstream LLM that can re-rank or summarize. -
use_bubbleenables bubble search which returns the matched chunk plus surrounding context rather than the chunk in isolation. Use it when chunks are small (e.g., per-paragraph) and the agent needs surrounding text to make sense of a match. Skip it when chunks are already large enough to be self-contained.
3. Search across multiple KBs from an agent
If your agent has more than one knowledge base attached,agent.knowledge_bases_retriever() returns a callable that searches all of them and merges results by score:
num_documents controls the merged result count. It’s the equivalent of top_k across the combined corpus.
Troubleshooting
Search returns no results
Search returns no results
Check that the KB has documents with
status=ready (see Document Management). A KB with all documents still processing or failed will return empty results. Also confirm the query isn’t empty and top_k is greater than 0.Scores are all very low
Scores are all very low
Low scores usually mean the query language doesn’t match the document language, or the content is too sparse. Try rephrasing the query to match how the documents describe the topic. If the corpus is large and diverse, raising
top_k and letting a downstream LLM re-rank often helps more than query reformulation.`knowledge_bases_retriever()` returns an empty list
`knowledge_bases_retriever()` returns an empty list
No KBs are attached to the agent. Attach at least one via the Workbench (agent’s KB tab) or via
agent.attach_knowledge_base(knowledge_base_id=...) in code. Then reload the agent before calling the retriever.Agent doesn't call the KB during reasoning
Agent doesn't call the KB during reasoning
For frameworks other than Agno, the retriever isn’t wired in automatically; you need to add it as a tool explicitly. See the framework pages for the per-framework setup. Also check that the agent is published after attaching the KB.
Next steps
Document management
Add, list, and remove documents from a KB programmatically.
Agent KB integration
How attached KBs reach the agent’s reasoning loop in each framework.
Output Response Filtering
Trim large KB responses before they reach the LLM.
KB SDK reference
Full method-level docs.

