Walk me through how you would design a RAG (Retrieval-Augmented Generation) system for a company's internal documentation chatbot.
Model answer
Pipeline: (1) Ingestion — parse documents (PDF, Confluence, Notion) and chunk them, typically 300-800 tokens with overlap to preserve context across boundaries; (2) Embedding — convert chunks to vectors using an embedding model (OpenAI text-embedding-3, Cohere, or an open-source model like BGE); (3) Storage — index embeddings in a vector database (Pinecone, Weaviate, pgvector) alongside metadata (source, date, access permissions); (4) Retrieval — on a user query, embed the query and run a similarity search (often hybrid: vector + keyword/BM25) to fetch top-k relevant chunks; (5) Re-ranking — optionally re-rank retrieved chunks with a cross-encoder for higher precision; (6) Generation — pass the query plus retrieved context into the LLM with a system prompt instructing it to answer only from the provided context and cite sources; (7) Guardrails — handle the "I don't know" case explicitly to reduce hallucination when retrieval confidence is low. Discuss trade-offs: chunk size affects both recall and context window cost; hybrid search improves recall for exact terms (product names, error codes) that pure vector search misses.
