This guide is for Python users building with xrag as a library.
xrag is a typed Python library for document ingest, chunk indexing,
retrieval, and retrieve-plus-generate workflows.
Use it when you want one library for:
- ingesting source documents into a vector-backed retrieval system
- indexing pre-chunked offline data
- retrieving typed chunks for your own LLM application
- running a full RAG flow from one client
xrag has three main entrypoints:
XragHigh-level async client for application coderun_ingest/run_ragLower-level functional API for callers that want directAppConfigcontrol- CLI Local workflows, debugging, artifact inspection, and evaluation runs
For most application code, start with Xrag.
from xrag import Xrag
client = Xrag(
qdrant_path="data/dev/xrag_quickstart",
generation="openai:gpt-4.1-nano",
)
doc = await client.documents.ingest("ir-sample-b.docx", collection="ir_docs")
result = await client.rag.ask(
query="What is this document about?",
collection="ir_docs",
)
print(doc.id)
print(result.answer)Runnable example:
doc = await client.documents.ingest(
"ir-sample-b.docx",
collection="ir_docs",
)Use this when you want xrag to run parser, chunker, embedding, and indexing for you.
Examples:
doc = await client.documents.index_chunks(
"data/chunks.json",
collection="ir_docs",
)Use this when your chunks already exist outside xrag's ingest path.
Examples:
result = await client.retrievals.search(
query="What was revenue?",
collection="ir_docs",
top_k=5,
)Use this when your application owns prompting and answer generation.
Example:
result = await client.rag.ask(
query="What was revenue?",
collection="ir_docs",
)Use this when you want xrag to do retrieval and answer generation in one call.
Examples:
The Xrag(...) constructor is the main application-facing config
surface.
Most users only need:
qdrant_urlorqdrant_pathembeddinggenerationif they useclient.rag.ask(...)
Example:
from xrag import Xrag
client = Xrag(
qdrant_url="http://localhost:6333",
embedding="openai:text-embedding-3-small",
generation="openai:gpt-4.1-nano",
)from xrag import Xrag
from xrag.config.models import RetrievalConfig
client = Xrag(
qdrant_url="http://localhost:6333",
qdrant_path=None,
embedding="openai:text-embedding-3-small",
generation="openai:gpt-4.1-nano",
enrichment=("auto_keywords", "auto_questions"),
reranker=None,
parser="unstructured",
chunker="section_table",
retrieval_defaults=RetrievalConfig(
provider="hybrid",
options={
"top_k": 10,
"bm25_candidates": 50,
"vector_candidates": 50,
"rrf_k": 60,
"dedup_family": False,
},
),
upload_dir="/tmp/xrag_uploads",
artifacts_dir=None,
timeout_s=30.0,
ingest_timeout_s=600.0,
tracing=None,
)qdrant_urlURL of a running Qdrant serverqdrant_pathLocal filesystem path for Qdrant local mode
Set exactly one of them.
embeddingEmbedding provider string used for indexing and retrievalgenerationAnswer-generation provider string used byrag.askrerankerOptional reranker configurationtracingOptional tracing backend configuration
parserParser provider configuration fordocuments.ingest. Default is the hostedunstructuredAPI parser.unstructured_local:fastworks for the lightweight local path in the base install. Addxrag[parser-unstructured-local-pdf]only for local PDF/OCR parsing.chunkerChunking strategy fordocuments.ingestenrichmentOptional ingest-time enrichment stagesupload_dirLocal spool location for bytes and file-like ingest inputsartifacts_dirBase location for ingest artifacts
retrieval_defaultsDefault retrieval config forretrievals.searchandrag.ask
timeout_sGeneral request timeoutingest_timeout_sIngest timeout budget
from xrag import Xrag
client = Xrag.from_env()Useful environment variables:
XRAG_QDRANT_URLXRAG_QDRANT_PATHXRAG_DEFAULT_EMBEDDINGXRAG_DEFAULT_GENERATIONXRAG_DEFAULT_RERANKERXRAG_UPLOAD_DIRXRAG_ARTIFACTS_DIR
If your application scopes operations by tenant:
acme = client.for_tenant("acme")
result = await acme.rag.ask(query="Summarise the risks.", collection="ir_docs")Example:
If your application already owns prompting, answer generation, or agent
logic, omit generation= and use xrag only for ingest plus retrieval.
client = Xrag(
qdrant_url="http://localhost:6333",
embedding="openai:text-embedding-3-small",
)Then call client.documents.* and client.retrievals.search(...).
All high-level client operations raise from XragError.
Catch specific subclasses when you need narrower behavior, such as:
XragCollectionNotFoundXragDocumentNotFoundXragChunksInvalidXragValidationErrorXragGenerationNotConfigured
Example:
../examples/01_quickstart.py../examples/02_from_env.py../examples/03_retrieve_only.py../examples/04_multi_tenant.py../examples/05_index_chunks.py../examples/05b_index_chunks_from_json.py../examples/06_export_and_validate.py../examples/06b_export_chunks.py../examples/07_error_handling.py../examples/08_per_call_overrides.py../examples/09_parse_docx_api_vs_local.py
../README.mdFast project entrypointsub-plans/xrag-public-api.mdDetailed API designcommand.mdCLI reference