Build a production-ready RAG pipeline using LangChain with conversational memory, source attribution, and streaming responses.
You are an expert AI engineer specializing in Retrieval-Augmented Generation systems. Build a complete LangChain RAG pipeline with the following specifications: ## Project Requirements - **Language**: [LANGUAGE e.g. Python 3.12] - **Vector Store**: [VECTOR_STORE e.g. Pinecone / Weaviate / pgvector] - **LLM Provider**: [LLM_PROVIDER e.g. OpenAI / Anthropic / local] - **Document Types**: [DOC_TYPES e.g. PDF, Markdown, HTML] - **Chunk Size**: [CHUNK_SIZE e.g. 512 tokens] - **Overlap**: [OVERLAP e.g. 50 tokens] ## Architecture 1. **Document Ingestion Layer**: Parse [DOC_TYPES] using appropriate loaders. Implement recursive text splitting with [CHUNK_SIZE] tokens and [OVERLAP] overlap. Add metadata extraction (source, page number, section headers). 2. **Embedding Pipeline**: Use [EMBEDDING_MODEL e.g. text-embedding-3-large] for vectorization. Implement batch embedding with retry logic and rate limiting. Cache embeddings to avoid re-computation. 3. **Retrieval Chain**: Configure [VECTOR_STORE] with HNSW indexing. Implement hybrid search (semantic + keyword BM25). Add MMR (Maximal Marginal Relevance) for diversity. Set top_k=[TOP_K e.g. 5] with similarity threshold=[THRESHOLD e.g. 0.75]. 4. **Conversation Memory**: Use ConversationBufferWindowMemory with k=[MEMORY_WINDOW e.g. 10] turns. Persist chat history to [STORAGE e.g. Redis / PostgreSQL]. Implement session management with unique conversation IDs. 5. **Response Generation**: Stream responses using async generators. Include source citations with chunk references. Add confidence scoring based on retrieval similarity. Implement hallucination guard using source verification. 6. **Production Hardening**: Add structured logging with correlation IDs. Implement circuit breaker for LLM API calls. Add request/response caching with TTL. Include Prometheus metrics for latency, token usage, and retrieval quality. Generate the complete implementation with all files, proper error handling, type hints, and comprehensive docstrings. Include a docker-compose.yml for local development and a requirements.txt with pinned versions.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro, Llama 4 Maverick.
Replace all [PARAMETER] placeholders with your specific values. Start with the document ingestion layer and test each component independently before integrating.
Initial release
Sign in and download this prompt to leave a review.