Learn how to build production RAG pipelines — from document ingestion and chunking to vector search and LLM generation. Architecture, costs, and pitfalls.
Ubikon Team
Development Experts
Retrieval-Augmented Generation (RAG) is an AI architecture pattern where a large language model generates responses grounded in data retrieved from an external knowledge base, rather than relying solely on its training data. At Ubikon, we build production RAG systems that power enterprise knowledge assistants, legal document search, and customer support platforms — reducing hallucination rates by 60–80% compared to vanilla LLM responses.
A RAG pipeline has three core stages:
Raw documents (PDFs, web pages, databases) are processed, chunked, embedded, and stored in a vector database.
Documents → Parser → Chunker → Embedding Model → Vector Database
When a user asks a question, the query is embedded and matched against stored vectors to retrieve the most relevant chunks.
User Query → Embedding → Vector Search → Top-K Chunks → Reranker → Final Context
The retrieved context is passed to an LLM along with the user query. The model generates an answer grounded in the provided documents.
System Prompt + Retrieved Context + User Query → LLM → Response
Single-step retrieval with direct LLM generation. Suitable for small-to-medium knowledge bases (under 10,000 documents).
Pros: Simple to build, fast iteration, low cost Cons: Struggles with complex multi-hop questions, limited by chunk size
Adds query transformation, hybrid search, reranking, and citation tracking.
Components:
The LLM decides when and how to retrieve information, can perform multi-step retrieval, and combines data from multiple sources.
Best for: Research assistants, complex enterprise Q&A, multi-source analysis
| Database | Self-Hosted | Managed | Best For |
|---|---|---|---|
| Pinecone | No | Yes | Fastest time-to-production |
| Weaviate | Yes | Yes | Hybrid search, multi-tenancy |
| Qdrant | Yes | Yes | Performance, filtering |
| pgvector | Yes | Yes | Teams already on PostgreSQL |
| Chroma | Yes | No | Prototyping, small datasets |
| Model | Dimensions | Quality | Cost |
|---|---|---|---|
| OpenAI text-embedding-3-large | 3072 | Excellent | $0.00013/1K tokens |
| Cohere embed-v3 | 1024 | Excellent | $0.0001/1K tokens |
| Voyage AI voyage-3 | 1024 | Excellent | $0.00012/1K tokens |
| BGE-large (open-source) | 1024 | Good | Free (self-hosted) |
Chunking is the single most impactful decision in your RAG pipeline. Get it wrong and nothing downstream can fix it.
Fixed-size chunking (400–800 tokens): Simple, predictable, works for homogeneous content
Semantic chunking: Split on topic boundaries using embedding similarity. Better for long-form content with distinct sections.
Document-aware chunking: Respect document structure — split on headings, sections, and paragraphs. Best for structured documents like legal contracts or technical documentation.
# Example: Document-aware chunking with overlap def chunk_document(text, max_tokens=500, overlap=50): sections = split_on_headings(text) chunks = [] for section in sections: if token_count(section) <= max_tokens: chunks.append(section) else: # Sub-chunk with overlap for context continuity sub_chunks = sliding_window(section, max_tokens, overlap) chunks.extend(sub_chunks) return chunks
| Component | Build Cost | Monthly Operation |
|---|---|---|
| Document ingestion pipeline | $3K–$8K | $50–$200 |
| Vector database | $2K–$5K setup | $100–$1,000 |
| Retrieval + reranking | $5K–$12K | $100–$500 |
| Generation layer | $3K–$8K | $200–$2,000 (API) |
| Evaluation framework | $2K–$5K | Engineering time |
| Total | $15K–$38K | $500–$3,700 |
RAG retrieves external data at inference time and includes it in the prompt. Fine-tuning modifies the model's weights using your data. RAG is better for factual Q&A over frequently changing data. Fine-tuning is better for teaching the model a specific style, format, or domain vocabulary. Many production systems use both — see our guide on LLM fine-tuning vs RAG.
RAG works with any amount of data — from 10 documents to millions. The architecture scales, but your chunking and retrieval strategies need to evolve. Under 1,000 documents, basic RAG works well. Over 100,000 documents, you need hierarchical retrieval, metadata filtering, and sophisticated reranking.
If you want the fastest path to production, use Pinecone. If you need self-hosting or hybrid search built in, use Weaviate or Qdrant. If your team already uses PostgreSQL, pgvector keeps your stack simple. For prototyping, Chroma is the easiest to set up.
Implement incremental indexing. Track document versions with hashes. When a document changes, delete old chunks and re-embed only the changed document. For real-time data (like support tickets), use a streaming ingestion pipeline that processes documents as they arrive.
Yes. Convert structured data (SQL tables, APIs) into natural language descriptions or use text-to-SQL approaches where the LLM generates database queries. For hybrid systems, combine vector search over unstructured documents with direct database queries for structured data.
Building a RAG pipeline for your product? Ubikon has delivered production RAG systems for legal tech, healthcare, and enterprise SaaS companies. Book a free consultation to get a technical architecture review and cost estimate tailored to your data and use case.
The exact playbook our founders use to ship MVPs in 8 weeks — without overspending on the wrong stack.
+ 20 more actionable checklist items
Ready to start building?
Get a free proposal for your project in 24 hours.
Was this page helpful?