RAG
Give your application searchable knowledge with named indexes, ingestion, and retrieval.
RAG connects document knowledge to AI responses. Your .NET host defines the sources, prepares searchable chunks, selects embedding and storage providers, and retrieves evidence for a question.
Start with a knowledge collection
Begin with a small set of documents and questions you can verify. Register a named index, ingest its content, then either query it directly or connect it to an agent.
Follow the document lifecycle
| Stage | Application responsibility |
|---|---|
| Define | Name the index and select sources, embedding model, and store. |
| Ingest | Read documents, split chunks, generate embeddings, and store records. |
| Retrieve | Search for candidate chunks relevant to the question. |
| Accept context | Apply the agent's relevance, result-count, and context policies. |
| Answer | Generate a response from accepted evidence and handle missing context. |
Index registration and agent configuration are separate. Registering a collection does not automatically make agents search it.
Choose the entry point
| Entry point | What it does |
|---|---|
IRagRetriever | Return candidates for application code to use. |
Agent.UseRag(...) | Retrieve and evaluate context as part of agent execution. |
Direct retrieval does not run an agent or apply its grounding policy. With required RAG and ReturnNotFound, a successful search with no accepted context skips the model and returns a framework-owned not-found response. Retrieval errors remain failures.
Install the packages
The OpenAI agent example also uses Runiq.AI.Agents. Its embedding model helpers are included in that package; selecting a model alone does not configure an embedding client or credentials.
For durable PostgreSQL storage:
The in-memory store is disposable and needs ingestion after every process restart. Choose persistent storage when documents and embeddings must survive restarts.
Choose a search mode
| Mode | Purpose |
|---|---|
| Semantic | Find related meaning with query embeddings and vector retrieval. |
| Lexical | Search precise terms using a lexical-capable store. |
| Hybrid | Combine semantic and lexical candidates; both sources must succeed. |
A retrieval score is not a confidence percentage. See Retrieval for score direction, relevance, and acceptance.
Build and inspect
| Guide | Outcome |
|---|---|
| Defining indexes | Register a collection and connect its agent. |
| Ingestion | Choose refresh triggers and inspect readiness. |
| Retrieval | Query directly or configure agent grounding. |
| PostgreSQL | Persist documents and run database-backed search. |
| Studio testing | Follow index readiness into an agent response. |
| Patterns | Align sources, storage, and failure behavior. |
Studio manages ingestion for indexes registered in code. It does not create indexes or attach them to agents. Retrieved text is treated as untrusted evidence; review whether the resulting answer is supported by its sources.