retrieve • AI Agent SDK
retrieve: Retrieve context from knowledge without LLM generation.
retrieve
Method
</div>
Retrieve context from knowledge without LLM generation.
Returns a ContextPack that can be passed to chat_with_context(). This enables conditional retrieval – only retrieve when needed.
Signature
def retrieve(query: str) -> 'ContextPack'Parameters
ParamField
strSearch query **kwargs: Additional arguments (top_k, rerank, etc.)
Returns
ResponseField
'ContextPack'ContextPack with context string and citations (no LLM call)
Exceptions
ValueError
If no knowledge is configured
ImportError
If RAG module is not available
Usage
agent = Agent(knowledge=["docs/"], retrieval_config={"citations": True})
context = agent.retrieve("What are the key findings?")
print(f"Found {len(context.citations)} sources")
response = agent.chat_with_context("Summarize", context)Uses
ValueErrorImportErrorkwargs.setdefaultretrieve
Used By
Source
View on GitHubpraisonaiagents/agent/agent.py at line 6824