Skip to main content
This complete example indexes two fictional store policies and exposes search as a tool. Install @agentium/core and openai, set OPENAI_API_KEY, and use the TypeScript project setup.
support.ts
Run it with npx tsx support.ts. The answer should cite [returns] and retain the staff-approval condition. Indexing and query embedding make provider calls; the in-memory store is rebuilt on each run.

Choose a persistent backend

InMemoryVectorStore takes an embedding provider. For a persisted application, choose an adapter from vector stores, create its indexes, and define document update/deletion behavior. Keep ingestion credentials and retrieval visibility scoped to the application.

Control the retrieval contract

KnowledgeBase.asTool() accepts a tool name, description, topK, score threshold, metadata filter, search mode, and result formatter. Search results expose id, content, score, and optional metadata directly. Format source IDs with the evidence so you can inspect an answer’s basis. A source ID in an answer does not prove grounding. Test questions with relevant documents, irrelevant documents, no supporting evidence, and content belonging to another tenant. Do not rely on a model instruction to enforce document visibility. Use hybrid search when you need the combined keyword/vector path, and reranking when your retrieval design calls for a second ranking stage. Evaluate the retrieval output before tuning the answer prompt. For a step-by-step explanation, continue with the tutorial chapter.