Direct Architectural Answer
AI Knowledge Assistant: Architecture & RAG Systems Guide
Comprehensive technical guide to building conversational AI assistants grounded in site-specific documentation through Retrieval-Augmented Generation (RAG). Covers: 4-stage pipeline (embed → retrieve → inject → generate), chunking strategies (500-1000 tokens, 10% overlap), embedding engines (text-embedding-3-small, Gemini), vector stores (PostgreSQL + pgvector for ACID compliance), and production guardrails. Schema.org TechArticle markup with implementation-ready architecture patterns.
Embed → Retrieve → Inject → Generate
PostgreSQL + pgvector (ACID)
Citations, hallucination detection, schema
Quick Answer: How Does a Website AI Assistant Work? (AEO Direct Answer)
An AI Website Assistant is a conversational agent grounded in site-specific documentation through Retrieval-Augmented Generation (RAG). When a user submits a question: (1) The query is converted into a vector embedding; (2) The vector database retrieves the top-k most semantically relevant text chunks; (3) The chunks are injected into the LLM system prompt as verified context; (4) The model streams back a factual, hallucination-free answer with direct citations. Unlike generic chatbots, a grounded knowledge assistant guarantees high precision through source attribution and factual grounding.
RAG Pipeline Architecture Breakdown
| Component | Technical Role | Recommended Implementation |
|---|---|---|
| Text Chunking | Splitting documentation into 500-1,000 token segments | RecursiveCharacterTextSplitter with 10% overlap |
| Embedding Engine | Generating dense mathematical vector representations | text-embedding-3-small (OpenAI) or text-embedding-004 (Gemini) |
| Vector Store | Executing high-speed cosine distance similarity search | PostgreSQL + pgvector (HNSW index, ACID compliant) |
| Retrieval | Hybrid BM25 + dense, reranking (Cohere, bge-reranker) | Top-k=5-10, rerank top-n=20, score threshold 0.7 |
| Generation | Cited answers, streaming, structured output | Temperature 0.0-0.1, citation format, JSON mode |
Why RAG Over Fine-Tuning for Knowledge Assistants?
| Factor | RAG | Fine-Tuning |
|---|---|---|
| Knowledge Updates | Instant (re-index docs) | Retrain required (hours-days) |
| Source Attribution | Native (chunk citations) | Not native (requires probes) |
| Hallucination Control | Grounding + verification | Implicit, harder to guarantee |
| Cost | Lower (embedding only) | Higher (GPU training) |
| Compliance | Data stays in vector DB | Model weights contain data |
Production Guardrails for Knowledge Assistants
# KNOWLEDGE ASSISTANT GUARDRAIL PIPELINE
1. INPUT VALIDATION
├── Query classification (on-topic vs. off-topic)
├── Prompt injection detection
├── PII redaction
└── Token budget enforcement
2. RETRIEVAL QUALITY
├── Hybrid search (BM25 + dense)
├── Reranking (Cohere v3.5 / bge-reranker)
├── Score threshold filtering (>0.7)
├── Diversity penalty (MMR)
└── Recency boost (if applicable)
3. CONTEXT INJECTION
├── Citation format: [Doc ID: chunk_index]
├── Context window budgeting (reserve 30% for generation)
├── Conflict detection (contradicting sources)
└── Source diversity enforcement
4. GENERATION CONTROL
├── Temperature: 0.0 (factual) → 0.1 (explanatory)
├── Structured output: JSON Schema with citations array
├── Stop sequences: ["", "```"]
├── Max tokens: 1024 (concise) / 2048 (detailed)
5. OUTPUT VERIFICATION
├── Schema validation (citations present, valid IDs)
├── Hallucination detection: self-consistency (n=3)
├── Citation verification: claim ↔ chunk alignment
├── Factual grounding: RAG context alignment score >0.8
├── Safety: content moderation API
└── Fallback: "I don't have enough information to answer accurately."
Chunking Strategy Deep-Dive
| Strategy | Chunk Size | Overlap | Best For |
|---|---|---|---|
| RecursiveCharacter | 500-1000 tokens | 10-15% | General docs, markdown, HTML |
| Markdown Header | Per section | 0% | Structured docs, preserves hierarchy |
| Code-Aware | Per function/class | 0% | Technical docs, API references |
| Token-Based | Fixed (512/1024) | 10% | Uniform retrieval, simple pipelines |
Embedding Model Selection
| Model | Dimensions | Context | Best For |
|---|---|---|---|
| text-embedding-3-small | 1536 | 8191 | General purpose, cost-effective |
| text-embedding-3-large | 3072 | 8191 | High accuracy, multilingual |
| text-embedding-004 (Gemini) | 768 | 2048 | Google ecosystem, cost-optimized |
| bge-large-en-v1.5 (local) | 1024 | 512 | Self-hosted, no API costs |
| E5-large-v2 (local) | 1024 | 512 | Instruction-tuned, strong retrieval |
Frequently Asked Questions (AEO FAQ)
Why PostgreSQL + pgvector over Pinecone/Qdrant?
PostgreSQL + pgvector (HNSW) provides: (1) ACID transactions — query relational metadata (permissions, dates, FKs) and vector similarity in one query; (2) Operational simplicity — single database to manage, backup, monitor; (3) Cost — no separate vector DB hosting; (4) Maturity — PostgreSQL ecosystem, pgvector is production-proven. Pinecone/Qdrant win at >100M vectors or when you need fully managed service.
What chunk size for technical documentation?
500-1000 tokens with 10% overlap for general docs. For code/API references: chunk per function/class (Markdown header or code-aware splitter). Avoid chunks >1500 tokens — dilutes retrieval precision and exceeds embedding model context efficiency.
How do I handle contradictory sources in RAG?
Detection: Compare retrieved chunks for semantic contradiction (embedding distance + LLM judge). Resolution: (1) Flag in answer: “Sources conflict on X…” (2) Prioritize: official docs > blog > forum; recent > older; specific > general. (3) Never synthesize — present both views with citations.
How do I evaluate RAG quality in production?
Metrics: Retrieval — Recall@k, MRR, NDCG. Generation — Faithfulness (claim ↔ context), Answer relevance, Citation accuracy. End-to-end — Human eval on golden set (50-100 Qs), A/B vs. non-RAG baseline. Tools: RAGAS, TruLens, LangSmith, custom eval harness. Run weekly on regression set.
Can RAG work for multilingual sites?
Yes. Use multilingual embeddings (text-embedding-3-large, E5, bge-m3). Chunk per language or use language-aware splitter. Retrieve with language filter. Generate in user’s language with citations in source language. Cross-lingual retrieval works but has lower precision.
Related Resources & Next Steps
- Open-Source AI Text Architecture — Self-hosted model deployment
- AI Text Generation Architectures — Model comparison & guardrails
- Technical Writing Guide — Document your RAG pipeline
- RAG Implementation Workshop — Expert deployment & optimization