RAG Knowledge Base
An team knowledge base: hybrid retrieval combining BM25 keyword search with vector semantic search, fused with Reciprocal Rank Fusion and cross-encoder reranking, plus Docling-powered document import that preserves images and tables.

Overview
C4Container
title Enterprise RAG Knowledge Base - Architecture
Person(user, "User", "Searches enterprise knowledge and asks questions")
Person(admin, "Knowledge Administrator", "Manages documents, indexing, and access permissions")
System_Boundary(rag, "Enterprise RAG Platform") {
Container(web, "Web Application", "React / TypeScript", "Knowledge management interface, document upload, search, and conversational query interface.")
Container(api, "Backend API", "FastAPI / REST API", "Handles authentication, authorization, document management, search requests, and orchestration.")
Container_Boundary(ingestion, "Document Ingestion Pipeline") {
Container(importer, "Document Importer", "Document Processing", "Accepts uploaded documents and manages ingestion workflows.")
Container(parser, "Document Parser", "Docling", "Extracts structured content from PDF, DOCX, and other supported formats while preserving document structure, tables, and images.")
Container(chunker, "Content Chunker", "Chunking Engine", "Splits extracted content into contextual chunks while preserving structural relationships and metadata.")
Container(embedding, "Embedding Service", "Embedding Model API", "Generates vector embeddings for document chunks and prepares content for semantic indexing.")
}
Container_Boundary(retrieval, "Hybrid Retrieval Pipeline") {
Container(query, "Query Processor", "Query Processing", "Normalizes user queries and generates query embeddings.")
Container(bm25, "Keyword Retriever", "BM25", "Retrieves candidate documents using full-text keyword matching.")
Container(vector, "Semantic Retriever", "Vector Search", "Retrieves semantically relevant chunks using embedding similarity.")
Container(rrf, "Rank Fusion", "Reciprocal Rank Fusion", "Combines keyword and semantic retrieval results into a unified candidate ranking.")
Container(reranker, "Reranking Engine", "Cross-Encoder", "Evaluates query-document relevance and reorders candidate chunks.")
Container(context, "Context Builder", "Context Assembly", "Assembles the highest-ranked chunks with source references for downstream AI generation.")
}
Container(llm, "LLM Service", "LLM API", "Generates context-aware responses based on retrieved knowledge.")
}
System_Boundary(storage, "Data Storage Layer") {
ContainerDb(metadata, "Metadata Database", "PostgreSQL", "Stores documents, metadata, permissions, indexing status, and document relationships.")
ContainerDb(vectors, "Vector Database", "PostgreSQL + pgvector", "Stores chunk embeddings and supports vector similarity search.")
ContainerDb(fulltext, "Full-Text Index", "PostgreSQL BM25 / Full-Text Search", "Maintains searchable text indexes for keyword retrieval.")
ContainerDb(objectstore, "Object Storage", "S3-Compatible Storage", "Stores original documents, extracted images, and associated binary assets.")
}
System_Ext(embedding_model, "Embedding Model Provider", "Generates document and query embeddings")
System_Ext(rerank_model, "Reranking Model Provider", "Provides cross-encoder relevance scoring")
System_Ext(llm_provider, "LLM Provider", "OpenAI-compatible or other LLM APIs")
Rel(user, web, "Uses")
Rel(admin, web, "Manages knowledge")
Rel(web, api, "HTTP / REST")
Rel(api, importer, "Submits documents")
Rel(importer, parser, "Processes documents")
Rel(parser, chunker, "Structured content")
Rel(chunker, embedding, "Text chunks")
Rel(embedding, embedding_model, "Embedding API")
Rel(embedding, vectors, "Stores embeddings")
Rel(chunker, fulltext, "Indexes extracted text")
Rel(importer, metadata, "Updates document metadata")
Rel(parser, objectstore, "Stores extracted images")
Rel(importer, objectstore, "Stores original files")
Rel(api, query, "Submits search queries")
Rel(query, embedding_model, "Generates query embeddings")
Rel(query, bm25, "Keyword query")
Rel(query, vector, "Semantic query")
Rel(bm25, fulltext, "Full-text retrieval")
Rel(vector, vectors, "Vector similarity search")
Rel(bm25, rrf, "Ranked candidates")
Rel(vector, rrf, "Ranked candidates")
Rel(rrf, reranker, "Merged candidates")
Rel(reranker, rerank_model, "Relevance scoring")
Rel(reranker, context, "Ranked chunks")
Rel(context, metadata, "Resolves source references")
Rel(context, llm, "Retrieved context")
Rel(llm, llm_provider, "Generation API")
Rel(llm, api, "Generated response")
Rel(api, web, "Search results and answers")
Rel(api, metadata, "Checks document permissions")
Rel(bm25, metadata, "Permission filtering")
Rel(vector, metadata, "Permission filtering")
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")
Enterprise Knowledge Base is a team-oriented knowledge management and retrieval platform designed to improve internal information discovery and knowledge accessibility.
The platform combines traditional full-text search with vector-based semantic retrieval to provide more accurate and context-aware search results. Its hybrid retrieval architecture integrates BM25 keyword search and dense vector search, using Reciprocal Rank Fusion (RRF) to merge results from both retrieval channels, followed by cross-encoder reranking to improve relevance and ranking precision.
Beyond retrieval, the platform provides a document ingestion and processing pipeline powered by Docling, enabling structured extraction of content from various document formats while preserving important elements such as tables, images, and document structure.
The overall architecture covers the complete knowledge retrieval lifecycle, from document ingestion and content extraction to chunking, embedding generation, indexing, hybrid retrieval, and relevance ranking.
Document Processing and Ingestion
Built a document ingestion pipeline powered by Docling to extract and normalize content from different document formats for knowledge indexing and retrieval.
The processing pipeline focuses on preserving document structure and semantic relationships rather than treating documents as plain text. It supports structured extraction of headings, paragraphs, tables, images, and other document elements.
Key capabilities include:
- Multi-Format Support: Import and process documents in common formats such as PDF, DOCX, and other supported file types.
- Structured Content Extraction: Extract document elements while retaining their structural relationships and hierarchy.
- Table Preservation: Preserve tabular content and convert it into structured representations suitable for indexing and retrieval.
- Image Handling: Extract and retain document images as associated content rather than discarding them during text conversion.
- Content Normalization: Normalize extracted content into a consistent internal representation for downstream processing.
- Intelligent Chunking: Split documents into retrieval-oriented chunks while maintaining meaningful content boundaries and contextual relationships.
Hybrid Retrieval Architecture
Implemented a hybrid search architecture combining BM25 keyword retrieval and vector-based semantic retrieval to address the limitations of relying on either approach independently.
BM25 provides precise lexical matching for technical terms, identifiers, product names, and domain-specific terminology, while vector retrieval captures semantic similarity and conceptual relationships even when queries and documents use different wording.
Both retrieval channels operate independently and contribute candidate results to a unified ranking pipeline.
Key capabilities include:
- BM25 Full-Text Search: Keyword-based retrieval for exact terms, technical expressions, identifiers, and terminology.
- Vector Semantic Search: Embedding-based retrieval that identifies semantically relevant content beyond literal keyword matching.
- Dual-Channel Retrieval: Executes keyword and semantic searches in parallel to improve recall and retrieval coverage.
- Configurable Retrieval: Supports different retrieval strategies and search modes to accommodate different query requirements.
- Permission-Aware Retrieval: Applies document access restrictions during candidate retrieval to ensure that search results respect user permissions.
Reciprocal Rank Fusion (RRF)
Integrated Reciprocal Rank Fusion (RRF) to combine independently ranked results from BM25 and vector retrieval into a unified candidate list.
Instead of directly comparing keyword relevance scores with vector similarity scores, RRF uses the relative ranking positions from each retrieval channel to calculate a combined ranking score.
This approach avoids score normalization inconsistencies between heterogeneous retrieval methods and provides a practical mechanism for balancing lexical and semantic relevance.
The fusion stage improves retrieval robustness by allowing documents identified through either retrieval channel to contribute to the final candidate set.
Cross-Encoder Reranking
Introduced a Cross-Encoder Reranking stage to refine the candidate results generated by hybrid retrieval.
Unlike bi-encoder vector retrieval, which independently encodes queries and documents for similarity comparison, a cross-encoder evaluates the query and each candidate document together to produce a more context-sensitive relevance score.
The reranking pipeline evaluates candidate chunks against the original query and reorders them according to their relevance, improving the quality of the final retrieval results.
Key capabilities include:
- Contextual Relevance Evaluation: Evaluates query-document relationships using joint input rather than embedding similarity alone.
- Candidate Reranking: Reorders hybrid retrieval results based on cross-encoder relevance scores.
- Relevance Refinement: Reduces the impact of loosely related results introduced by broad keyword or semantic retrieval.
- Retrieval Pipeline Integration: Combines candidate generation, rank fusion, and semantic reranking into a unified retrieval workflow.
Knowledge Indexing and Embedding
Established an indexing pipeline that transforms processed documents into searchable knowledge units.
Document content is divided into contextual chunks, which are converted into vector embeddings and stored alongside associated document metadata. The indexing process supports both traditional full-text indexing and vector indexing, allowing the same knowledge content to participate in multiple retrieval strategies.
Key capabilities include:
- Document Chunking: Organizes content into smaller retrieval units while preserving contextual boundaries.
- Embedding Generation: Converts text chunks into dense vector representations using configurable embedding models.
- Hybrid Indexing: Maintains keyword-searchable content and vector representations for dual-channel retrieval.
- Metadata Association: Preserves document identifiers, source references, and contextual information for result traceability.
- Index Management: Supports document processing and indexing workflows to keep searchable knowledge synchronized with source content.
End-to-End RAG Retrieval Pipeline
Combines document processing, hybrid retrieval, rank fusion, and reranking into an integrated Retrieval-Augmented Generation (RAG) architecture.
The overall workflow consists of two major stages:
Knowledge Ingestion Pipeline
- Document import and format detection.
- Structured content extraction using Docling.
- Content normalization and intelligent chunking.
- Embedding generation for document chunks.
- Full-text and vector index construction.
Query Retrieval Pipeline
- Receive the user query.
- Generate a query embedding.
- Execute BM25 keyword retrieval and vector semantic retrieval in parallel.
- Merge candidate results using Reciprocal Rank Fusion.
- Apply cross-encoder reranking to refine relevance.
- Return the highest-ranked knowledge chunks with source references for downstream applications.
This architecture separates candidate recall from relevance refinement, providing a flexible foundation for accurate enterprise knowledge retrieval and downstream AI applications.
Technical Architecture
- Document Processing: Docling, structured document extraction, table and image preservation.
- Search Engine: BM25, PostgreSQL full-text search.
- Vector Retrieval: Dense embeddings, vector similarity search, vector indexing.
- Hybrid Search: Parallel retrieval, Reciprocal Rank Fusion (RRF).
- Reranking: Cross-Encoder relevance scoring and candidate reordering.
- RAG Pipeline: Document ingestion, chunking, embedding, retrieval, and contextual result assembly.
- Knowledge Management: Document organization, metadata management, and permission-aware retrieval.
- Model Integration: Configurable embedding and reranking model providers.


