Building an AI Company Knowledge Base: Architecture and Implementation

TL;DR — An AI company knowledge base uses RAG, vector search, and knowledge graphs to answer employee questions from company documents with source citations. Unlike a traditional wiki, it understands natural language, retrieves across all connected sources, and synthesizes answers. The architecture has five layers: (1) ingestion pipeline connecting to Google Drive, Slack, Confluence, Notion, and GitHub, (2) hybrid retrieval with BM25 + vector search and RRF fusion, (3) LLM generation with citations, (4) permissions enforcement at the chunk level, and (5) hallucination prevention with confidence thresholds. Self-hosted deployment (pgvector, OpenSearch, Qdrant) keeps data in your infrastructure with no per-user costs. For >100 users or regulated data, self-hosting is more cost-effective than SaaS ($10-30/user/month).

A company knowledge base is the foundation of enterprise AI. Without it, your AI assistant is a chatbot that makes things up. With it, your AI answers questions grounded in your company's actual documents, policies, and data.

The difference between a company brain and a traditional wiki is the difference between asking a colleague who knows your company and searching a filing cabinet. The colleague understands your question, finds the right information across multiple sources, and gives you a direct answer with context. The filing cabinet requires you to know which folder to look in.

Traditional Knowledge Base vs AI Knowledge Base

Dimension Traditional Wiki/KB AI Knowledge Base
Query type Keyword search, navigation Natural language questions
Answer format Document links Synthesized answers with citations
Source coverage One system at a time All connected sources simultaneously
Permissions Manual per-document Inherited from source, enforced in retrieval
Multi-hop reasoning None Knowledge graph traversal
Freshness Manual updates Incremental ingestion pipeline
User experience "Find the right doc" "Ask and get an answer"
Setup complexity Low (out of box) Medium (ingestion pipeline, vector store)

Architecture: Five Layers

flowchart TD subgraph Sources["Data Sources"] Drive["Google Drive"] Slack["Slack"] Confluence["Confluence"] Notion["Notion"] GitHub["GitHub"] end subgraph Ingestion["Layer 1: Ingestion Pipeline"] Connectors["Source Connectors"] Chunking["Document Chunking"] Embedding["Vector Embedding"] ACL["ACL Tagging"] end subgraph Retrieval["Layer 2: Hybrid Retrieval"] BM25["BM25 Search"] Vector["Vector Search"] RRF["RRF Fusion"] Reranker["Cross-Encoder Rerank"] end subgraph Generation["Layer 3: LLM Generation"] Context["Context Assembly
(with ACL filtering)"] LLM["LLM Synthesis"] Citations["Citation Tagging"] end subgraph Trust["Layer 4: Trust & Safety"] Faithfulness["Faithfulness Check"] Confidence["Confidence Threshold"] Hallucination["Hallucination Detection"] end subgraph Access["Layer 5: Access Control"] Auth["User Authentication"] ACLFilter["ACL Filtering"] Audit["Audit Logging"] end Sources --> Ingestion Ingestion --> Retrieval Retrieval --> Generation Generation --> Trust Trust --> Access Access --> Answer["Source-Cited Answer"]

Layer 1: Ingestion Pipeline

The ingestion pipeline connects to your existing tools and indexes their content:

class IngestionPipeline:
    """Ingest documents from multiple sources with ACL tagging."""

    SOURCES = {
        "google_drive": GoogleDriveConnector,
        "slack": SlackConnector,
        "confluence": ConfluenceConnector,
        "notion": NotionConnector,
        "github": GitHubConnector,
    }

    def ingest_source(self, source: str, config: dict) -> dict:
        connector = self.SOURCES[source](config)

        stats = {"documents": 0, "chunks": 0, "errors": []}

        for document in connector.fetch_documents():
            # Chunk the document
            chunks = self._chunk_document(document)

            for chunk in chunks:
                # Tag with ACL from source document
                chunk["acl"] = document.permissions
                chunk["source_doc"] = document.title
                chunk["source_url"] = document.url
                chunk["source_system"] = source
                chunk["ingested_at"] = datetime.utcnow()

                # Generate embedding
                chunk["embedding"] = self._embed(chunk["content"])

                # Store in vector database with metadata
                self.vector_store.upsert(chunk)
                stats["chunks"] += 1

            stats["documents"] += 1

        return stats

    def _chunk_document(self, document, chunk_size=512, overlap=50):
        """Split document into overlapping chunks."""
        text = document.content
        chunks = []
        start = 0

        while start < len(text):
            end = start + chunk_size
            chunk_text = text[start:end]

            chunks.append({
                "content": chunk_text,
                "chunk_index": len(chunks),
                "char_start": start,
                "char_end": end,
            })

            start += chunk_size - overlap

        return chunks

Layer 2: Hybrid Retrieval

Hybrid retrieval combines BM25 and vector search with RRF fusion:

class KnowledgeBaseRetriever:
    """Retrieve relevant chunks with hybrid search and ACL filtering."""

    def retrieve(self, query: str, user_id: str, top_k: int = 10) -> list:
        # Get user's permissions
        user_acls = self.acl_service.get_user_permissions(user_id)

        # Run BM25 and vector search in parallel
        bm25_results = self.bm25_store.search(
            query, top_k=top_k * 3, filter_acl=user_acls
        )
        vector_results = self.vector_store.search(
            query_embedding=self._embed(query),
            top_k=top_k * 3, filter_acl=user_acls
        )

        # RRF fusion
        fused = self._rrf_fuse(bm25_results, vector_results)

        # Cross-encoder reranking
        reranked = self.reranker.rerank(query, fused[:top_k * 2])

        return reranked[:top_k]

Layer 3: LLM Generation with Citations

class KnowledgeBaseGenerator:
    """Generate answers with citations from retrieved context."""

    SYSTEM_PROMPT = """You are a company knowledge assistant. Answer the user's 
    question using ONLY the provided context. Cite sources using [N] notation.
    If the context doesn't contain the answer, say "I don't have enough 
    information to answer this question."

    Context:
    {context}
    """

    def generate(self, query: str, retrieved_chunks: list) -> dict:
        # Format context with citation IDs
        context = self._format_context(retrieved_chunks)

        # Generate answer
        answer = self.llm.generate(
            system_prompt=self.SYSTEM_PROMPT.format(context=context),
            user_query=query
        )

        # Verify citations
        citation_check = self._verify_citations(answer, retrieved_chunks)

        return {
            "answer": answer,
            "citations": citation_check["valid_citations"],
            "fake_citations": citation_check["fake_citations"],
            "sources": retrieved_chunks[:5],
        }

Layer 4: Trust & Safety

  • Faithfulness check: decompose answer into claims, verify each against context
  • Confidence threshold: if retrieval scores are low, return "I don't know"
  • Hallucination detection: flag answers with uncited claims

Layer 5: Access Control

  • User authentication: verify identity before query
  • ACL filtering: only retrieve chunks the user has permission to see
  • Audit logging: log every query, retrieval, and answer for compliance

Self-Hosted vs SaaS

Factor Self-Hosted SaaS (Guru, Glean, Stonly)
Data sovereignty ✅ Full control ❌ Data leaves your infra
Per-user cost None $10-30/user/month
Setup time Days to weeks Hours
Maintenance Your team Vendor handles
Customization Full control Limited to vendor features
Compliance Full control Depends on vendor certifications
Scale cost Infrastructure only Linear with user count
Best for >100 users, regulated data <100 users, fast deployment

For 200 users at $20/user/month, SaaS costs $48,000/year. A self-hosted solution (pgvector + OpenSearch + local LLM) costs ~$15,000/year in infrastructure. The break-even point is typically around 75-100 users.

Technology Stack for Self-Hosted AI Knowledge Base

Component Technology Options Purpose
Vector store pgvector, Qdrant, Weaviate Store and search embeddings
Full-text search OpenSearch, Elasticsearch BM25 keyword search
Knowledge graph FalkorDB, Neo4j, Apache AGE Multi-hop reasoning
LLM Llama 3, Mistral (self-hosted) or API Answer synthesis
Embedding model BGE, E5, OpenAI embeddings Vector representations
Reranker BGE-reranker, Cohere rerank Precision boost
Source connectors Nango, custom connectors Connect to Google Drive, Slack, etc.
Database PostgreSQL Metadata, ACLs, audit logs
Framework FastAPI, LangChain, LlamaIndex Orchestration

AI Knowledge Base Implementation Checklist

  • [ ] Inventory data sources: Google Drive, Slack, Confluence, Notion, GitHub, internal DBs
  • [ ] Choose deployment: self-hosted (pgvector/OpenSearch) or SaaS
  • [ ] Set up source connectors with OAuth credential isolation
  • [ ] Implement document chunking (512 tokens, 50 overlap is a good start)
  • [ ] Generate vector embeddings for each chunk
  • [ ] Tag every chunk with source document ACL metadata
  • [ ] Set up BM25 full-text index alongside vector index
  • [ ] Configure hybrid retrieval with RRF (k=60)
  • [ ] Add cross-encoder reranking for top candidates
  • [ ] Implement ACL filtering in retrieval pipeline
  • [ ] Configure LLM system prompt with citation requirements
  • [ ] Implement citation verification (detect fake citations)
  • [ ] Set confidence threshold for "I don't know" responses
  • [ ] Add faithfulness evaluation on generated answers
  • [ ] Set up incremental ingestion (update index when documents change)
  • [ ] Implement content hash deduplication to avoid re-indexing
  • [ ] Configure audit logging for all queries and answers
  • [ ] Test with real enterprise queries from different departments
  • [ ] Measure answer quality: faithfulness, groundedness, relevance
  • [ ] Monitor retrieval latency (target: <200ms for hybrid search)
  • [ ] Consider temporal knowledge graphs for versioned facts
  • [ ] Integrate with company brain architecture
  • [ ] Set up monitoring: query volume, refusal rate, hallucination rate
  • [ ] Create feedback loop: users flag bad answers for review

FAQ

What is an AI company knowledge base?

An AI company knowledge base is a searchable knowledge infrastructure that uses AI (RAG, vector search, knowledge graphs) to answer employee questions from company documents. Unlike a traditional wiki or document management system, an AI knowledge base understands natural language queries, retrieves relevant information across all connected sources, and generates source-cited answers. It connects to existing tools (Google Drive, Slack, Confluence, Notion) and enforces document-level permissions.

How is an AI knowledge base different from a traditional wiki?

A traditional wiki requires users to navigate to the right document and read it. An AI knowledge base lets users ask questions in natural language and get synthesized answers with citations. Traditional wikis rely on manual categorization and search. AI knowledge bases use vector search for semantic retrieval, BM25 for exact matching, and LLMs for answer synthesis. Traditional wikis don't understand relationships between documents; AI knowledge bases can use knowledge graphs for multi-hop reasoning.

What sources should an AI company knowledge base connect to?

An AI knowledge base should connect to the tools where your company already creates and stores knowledge: Google Drive or SharePoint for documents, Confluence or Notion for wikis, Slack or Teams for conversations, Jira or Linear for tickets, GitHub for code and documentation, and internal databases. The key is connecting to existing sources rather than requiring users to copy content into a new system. Each source must maintain its original permissions.

How do you enforce permissions in an AI knowledge base?

Permissions enforcement requires document-level ACLs (Access Control Lists) throughout the pipeline: during ingestion (tag each chunk with its source document's ACL), during retrieval (filter results by the user's permissions), and during generation (never include content the user can't access). The vector store must support metadata filtering. If a user doesn't have access to a document, chunks from that document must not appear in retrieval results or in the LLM context.

Should you self-host or use a SaaS AI knowledge base?

Self-host when data sovereignty, compliance, or cost at scale matter. SaaS AI knowledge bases (Guru, Glean, Stonly) are faster to deploy but send your data to third parties and cost $10-30/user/month. Self-hosted solutions (using pgvector, OpenSearch, or Qdrant) keep data in your infrastructure, have no per-user costs, and give full control over retrieval and generation. For enterprises with >100 users or regulated data, self-hosting is typically more cost-effective and compliant.


Want a self-hosted AI company brain that does all of this out of the box?
Book a demo →