RAG Pipeline
Document Ingestion
- User uploads a document (PDF, DOCX, Markdown, TXT, HTML)
- Document processor extracts text and metadata
- Text is split into semantic chunks with heading paths and page numbers
- Chunks are embedded using the configured embedding provider
- Chunks and embeddings are stored in the database
Retrieval
When a user asks a question:
- Query is embedded using the same embedding provider
- Vector search finds semantically similar chunks
- Full-text search finds keyword-matching chunks
- Reciprocal Rank Fusion (RRF) combines both result sets
- Top-K chunks are selected as context
Generation
- Retrieved chunks are formatted into a grounding prompt
- The LLM generates a response with inline citations
- Response streams to the client via SSE
- Citations are extracted and stored in the database
Citation Extraction
After generation, the system:
- Parses citation markers from the LLM response
- Matches each citation to its source chunk
- Stores citation records with document, chunk, page, and heading metadata
- Emits a
citations_storedevent to the client with citation IDs
