Your First RAG Query
This tutorial walks you through uploading a document, understanding how it gets processed, and querying it with Retrieval-Augmented Generation (RAG).
What is RAG?
Retrieval-Augmented Generation combines a language model with a retrieval system. Instead of relying solely on the model's training data, RAG fetches relevant context from your documents and injects it into the prompt — producing answers grounded in your actual data.
[!TIP] Zyrabit uses hybrid retrieval — combining BM25 keyword matching with vector similarity search — for significantly better recall than either method alone.
Step 1: Start the Stack
Make sure your Zyrabit stack is running:
./zyra.sh start
Verify health:
curl http://localhost:8080/v1/health
Expected response:
{"status": "healthy", "chroma": "connected", "inference": "connected"}
Step 2: Upload a Document
Upload a PDF, DOCX, or text file via the API:
curl -X POST http://localhost:8080/v1/ingest \
-H "Authorization: Bearer $ZYRABIT_API_KEY_MCP" \
-F "file=@/path/to/your/document.pdf"
Or simply drag and drop files into the Web UI at http://localhost:8080.
What Happens Behind the Scenes
When you upload a document, Zyrabit processes it through this pipeline:
- Document Parsing — The
DocumentUseCasedetects the file type and applies the correct strategy (PDF, DOCX, TXT, audio transcription via Whisper). - Chunking — The document is split into overlapping chunks optimized for retrieval.
- Embedding — Each chunk is converted to a vector embedding using the configured embedding model.
- Indexing — Vectors are stored in ChromaDB (or your configured vector store). A BM25 index is also built in memory for keyword matching.
[!NOTE] Audio files (
.mp3,.wav,.m4a) are automatically transcribed using Whisper before being chunked and indexed. No extra configuration needed.
Step 3: Query with RAG
Now ask a question about your uploaded document:
curl -X POST http://localhost:8080/v1/chat \
-H "Authorization: Bearer $ZYRABIT_API_KEY_MCP" \
-H "Content-Type: application/json" \
-d '{"text": "What are the key findings in the report?"}'
The RAG Pipeline in Action
When your query hits the API, here's what happens inside ChatUseCase.execute():
- PII Masking — The
Gatekeeperscans your input for PII (emails, phone numbers, credit cards) and replaces them with tokens like<USER_EMAIL_1>. - Routing — The
Gatekeeperdecides:"rag"(query needs document context) or"direct"(general question). - Hybrid Retrieval — If routed to RAG, the
HybridRetrieverServiceruns both:- BM25 — keyword-based search across the in-memory index
- Vector Search — cosine similarity search in ChromaDB
- Results are fused and ranked by relevance
- Context Injection — The top chunks are injected into the system prompt as context.
- Inference — The composed prompt is sent to the local LLM via the
InferencePort. - PII De-anonymization — Tokens like
<USER_EMAIL_1>are replaced back with original values before returning. - Caching — The response is cached by
client_msg_idto prevent duplicate processing.
Expected Response
{
"response": "Based on the uploaded report, the key findings include...",
"sources": [
{"chunk": "...", "score": 0.89},
{"chunk": "...", "score": 0.85}
]
}
Next Steps
- Learn about the Hexagonal Architecture that makes this pipeline modular
- Swap the database from ChromaDB to PostgreSQL/pgvector
- Configure models for different inference providers
- Explore the full API Reference