Retrieve first, then answer
This function owns an in-memory knowledge base and an Agent. It loads two fictional store policies, retrieves evidence, and returns both the answer and source IDs. The supplied model and embedder must already be configured by your application.returns and the answer to cite that ID with the 30-day policy. The prompt requests grounding; verify it with application evaluations rather than treating a citation as proof.
Change one policy and repeat the question. Also ask about a fact absent from both documents: the answer should acknowledge missing evidence. This small fixture rebuilds its index for each invocation; a service should ingest separately and reuse its owned index.
Let an Agent decide when to search
Host factory: pass an initialized knowledge base populated with documents visible to this caller. This function borrows it. The host closes the Agent after its runs and the knowledge base after all consumers finish.search_policy in the run’s tool events and inspect its result. Giving the model a search tool does not guarantee it will call it. Choose retrieval-before-generation when your application requires evidence to be present on every request.
Choose the storage and retrieval path
Metadata filters are part of retrieval configuration, not a substitute for authorizing document ingestion and access. Keep source IDs stable and retain the source revision used by an answer.