haystack
**Haystack** is an **open-source, production-oriented NLP framework by Deepset for building modular search systems, RAG pipelines, and conversational AI applications** — offering a component-based pipeline architecture that gives engineering teams fine-grained control over each stage of document retrieval, processing, and generation without the tight coupling found in higher-level frameworks.
**What Is Haystack?**
- **Definition**: A Python framework from Deepset (Berlin, founded 2018) for assembling NLP and LLM-powered applications from interchangeable, production-hardened components connected via explicit pipelines.
- **Pipeline Architecture**: Applications are built as directed graphs of components — a DocumentStore feeds a Retriever which feeds a Reader or Generator — making the data flow explicit, inspectable, and testable.
- **Document Stores**: Native integration with ElasticSearch, OpenSearch, Weaviate, Pinecone, Qdrant, Milvus, and PostgreSQL with pgvector — store documents once, query via BM25 or dense vector retrieval.
- **Hybrid Retrieval**: Combine keyword search (BM25) with dense semantic search (DPR, ColBERT) and merge results with Reciprocal Rank Fusion — achieving better recall than either method alone.
- **Haystack 2.0**: Redesigned in 2024 with a composable component system, dataclasses-based typing, and first-class support for agentic pipelines and streaming.
**Why Haystack Matters**
- **Production Orientation**: Components are designed for production — built-in batching, async support, connection pooling, and structured error handling that LangChain's rapid iteration cycle sometimes sacrifices.
- **Explainability**: Explicit pipeline graphs make it easy to inspect what happened at each stage — critical for debugging retrieval failures and auditing enterprise RAG systems.
- **Enterprise Search Backbone**: Deepset's commercial product (Haystack Cloud) runs Haystack at scale for enterprise search use cases — the framework is shaped by real production requirements.
- **Modular Replacement**: Swap any component without rewriting the pipeline — replace OpenSearch with Weaviate, or switch from a Reader to a GPT-4 Generator, with minimal code changes.
- **Open Source Community**: 15,000+ GitHub stars, active contributor community, and extensive documentation with domain-specific examples (legal search, medical Q&A, code search).
**Core Haystack 2.0 Components**
**Retrievers**:
- **BM25Retriever**: Classic keyword-based retrieval — fast, no embeddings needed, great for exact match queries.
- **EmbeddingRetriever**: Dense semantic retrieval using sentence transformers or OpenAI embeddings.
- **HybridRetriever**: Weighted combination of BM25 and embedding scores for best-of-both-worlds retrieval.
**Document Processing**:
- **Converters**: PDF, DOCX, HTML, CSV to Document objects — preprocessing for ingestion pipelines.
- **PreProcessors**: Sentence splitting, sliding window chunking, deduplication — control over chunk boundaries.
- **DocumentJoiner**: Merges results from parallel retrieval branches with configurable scoring strategies.
**Generators**:
- **OpenAIGenerator**: GPT-4/GPT-3.5 with streaming support and tool calling.
- **AnthropicGenerator**: Claude 3 family with extended context windows.
- **HuggingFaceLocalGenerator**: Run open-weight models locally with llama.cpp or transformers.
**Building a RAG Pipeline**
```python
from haystack import Pipeline
from haystack.components.retrievers import InMemoryBM25Retriever
from haystack.components.generators import OpenAIGenerator
pipeline = Pipeline()
pipeline.add_component("retriever", InMemoryBM25Retriever(document_store=store))
pipeline.add_component("generator", OpenAIGenerator(model="gpt-4"))
pipeline.connect("retriever.documents", "generator.documents")
result = pipeline.run({"retriever": {"query": "What is the refund policy?"}})
```
**Haystack vs LangChain vs LlamaIndex**
| Aspect | Haystack | LangChain | LlamaIndex |
|--------|---------|-----------|-----------|
| Architecture | Explicit pipelines | Chain/runnable | Query engines |
| Production focus | Very high | Medium | Medium-high |
| Search integration | Very deep | Moderate | Moderate |
| Enterprise search | Excellent | Good | Good |
| Community | Large | Very large | Large |
| Debugging | Excellent | Variable | Good |
Haystack is **the framework of choice for teams building production-grade search and RAG systems who need explicit control, modularity, and enterprise reliability** — its component-based pipeline model makes complex multi-stage retrieval systems as debuggable and maintainable as standard software, bringing software engineering discipline to the often-chaotic world of LLM application development.