Skip to main content
query() is the read workflow. It embeds a user question, searches the vector database, and returns matching chunks. Use query() when your app needs search results. Use chat() when your app needs an answer with sources. In SDK examples, RagRails(...) holds the default collection, vector store, embedding model, LLM, and reranker. The query() or chat() call only repeats those settings when it is intentionally overriding them for that run.

Basic Query

Use Basic Query when you want ranked chunks back from the knowledge base.

Reranked Query

Use reranking when vector search returns good candidates but you want a second ranking model to reorder the final results.

Query Rewrite

Use query rewrite for follow-up questions that need conversation context before retrieval.
Pure query rewrite is currently SDK-only because it needs an LLM object. CLI and REST expose query rewrite through chat, where the LLM provider can be configured as part of the request.

Chat Answers

Use chat when you want a grounded natural-language answer instead of raw chunks. Chat is stateless: save the returned history and pass it to the next turn.

Configuration

SDK defaults live on the RagRails(...) instance. CLI defaults come from .ragrails.toml or flags. REST defaults come from each request payload and any server-side configuration.

Response Fields

Query

Chat

Possible Errors

query() can return retrieval and validation errors. chat() can return retrieval, generation, or quality errors.
For lower-level search-only controls, see Retrieval. For answer-generation controls, see Chat.