Haystack — AI Orchestration for Search & RAG
Open-source AI orchestration framework by deepset. Build production RAG pipelines, semantic search, and agent workflows with modular components. 25K+ GitHub stars.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 761bd107-7156-4c62-b268-62a3fb9818dc --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
Haystack is an open-source Python framework by deepset for building AI applications focused on retrieval-augmented generation (RAG) and semantic search. It provides a pipeline architecture where you compose components (document stores, retrievers, generators, readers) into end-to-end workflows. Haystack handles the plumbing between components: data serialization, error propagation, and execution ordering.
The framework supports multiple LLM providers (OpenAI, Anthropic, Cohere, local models), multiple document stores (Elasticsearch, Qdrant, Pinecone, Weaviate, ChromaDB), and multiple embedding models. This flexibility lets you swap backends without rewriting pipeline logic.
How it saves time or tokens
Building a RAG pipeline from scratch involves connecting a document store, embedding model, retriever, prompt builder, and LLM generator. Each connection requires data transformation, error handling, and configuration. Haystack provides pre-built components for each step and a pipeline abstraction that handles data flow between them.
The framework also includes production-critical features that developers often forget to build: document deduplication, metadata filtering, hybrid retrieval (combining semantic and keyword search), and evaluation tools for measuring pipeline quality. These features prevent the common failure mode where a RAG system works in demos but fails in production due to poor retrieval quality.
How to use
- Install Haystack:
```bash
pip install haystack-ai
```
- Build a simple RAG pipeline:
```python
from haystack import Pipeline
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder
prompt = PromptBuilder(
template='Answer: {{query}}\nContext: {{documents}}'
)
generator = OpenAIGenerator(model='gpt-4o')
pipeline = Pipeline()
pipeline.add_component('prompt', prompt)
pipeline.add_component('generator', generator)
pipeline.connect('prompt', 'generator')
```
- Add a document store and retriever for full RAG.
Example
Complete RAG pipeline with document indexing and retrieval:
from haystack import Pipeline, Document
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.embedders import (
OpenAIDocumentEmbedder,
OpenAITextEmbedder,
)
from haystack.components.retrievers.in_memory import (
InMemoryEmbeddingRetriever,
)
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder
# 1. Index documents
doc_store = InMemoryDocumentStore()
embedder = OpenAIDocumentEmbedder()
docs = [
Document(content='Haystack is a RAG framework by deepset.'),
Document(content='Pipelines compose components into workflows.'),
]
embedded = embedder.run(documents=docs)
doc_store.write_documents(embedded['documents'])
# 2. Build query pipeline
query_pipeline = Pipeline()
query_pipeline.add_component('embedder', OpenAITextEmbedder())
query_pipeline.add_component('retriever',
InMemoryEmbeddingRetriever(document_store=doc_store))
query_pipeline.add_component('prompt', PromptBuilder(
template='Context: {{documents}}\nQuestion: {{query}}\nAnswer:'))
query_pipeline.add_component('generator', OpenAIGenerator())
query_pipeline.connect('embedder.embedding', 'retriever.query_embedding')
query_pipeline.connect('retriever', 'prompt.documents')
query_pipeline.connect('prompt', 'generator')
result = query_pipeline.run({
'embedder': {'text': 'What is Haystack?'},
'prompt': {'query': 'What is Haystack?'},
})
print(result['generator']['replies'][0])
Related on TokRepo
- AI Tools for RAG — Compare Haystack with other RAG frameworks and tools.
- AI Tools for Research — Explore research tools that use semantic search and retrieval.
Common pitfalls
- Confusing Haystack 1.x with 2.x APIs. Version 2.0 was a complete rewrite with a new pipeline architecture and component API. Tutorials and code from version 1.x will not work with 2.x. Always check that examples match your installed version.
- Using in-memory document stores for production. InMemoryDocumentStore is great for development but loses all data on restart. For production, use a persistent backend like Elasticsearch, Qdrant, or Pinecone.
- Not evaluating retrieval quality. A RAG pipeline is only as good as its retriever. Haystack includes evaluation components to measure retrieval recall and answer quality. Use these before deploying to catch poor retrieval performance.
常见问题
Haystack is focused on search, retrieval, and RAG pipelines with deep document store integrations. LangChain is a broader toolkit for building LLM applications including agents, chains, and memory. Haystack provides stronger abstractions for document processing and retrieval evaluation. LangChain provides more flexibility for general-purpose LLM workflows.
Haystack supports Elasticsearch, OpenSearch, Qdrant, Pinecone, Weaviate, ChromaDB, Milvus, and an in-memory store for development. Each store has a dedicated integration package. The pipeline abstraction means you can swap stores by changing one component without modifying the rest of the pipeline.
Yes. Generator components in Haystack support streaming, delivering tokens to the caller as they are generated. This is important for chat-like interfaces where users expect to see the response build incrementally rather than waiting for the full response.
Yes. Haystack supports local models through Ollama, Hugging Face Transformers, and any OpenAI-compatible API endpoint. For local embeddings, use sentence-transformers models. This enables fully local RAG pipelines with no external API dependencies.
Haystack pipelines can be serialized to YAML for reproducible deployment. Deploy the pipeline as a REST API using FastAPI or Flask, containerize with Docker, and serve behind a load balancer. deepset also offers Haystack Cloud for managed pipeline deployment.
引用来源 (3)
- Haystack GitHub Repository— Haystack is an open-source RAG framework by deepset
- Haystack Documentation— Haystack pipeline architecture and components
- Haystack Integrations— deepset Haystack integrations with document stores
来源与感谢
Created by deepset. Licensed under Apache 2.0. deepset-ai/haystack — 25,000+ GitHub stars
讨论
相关资产
Haystack — Production RAG & Agent Framework
Build composable AI pipelines for RAG, agents, and search. Model-agnostic, production-ready, by deepset. 18K+ stars.
PraisonAI — Multi-Agent AI Orchestration Framework
PraisonAI is a production-ready framework for building autonomous AI agent workflows. It combines multi-agent orchestration with built-in memory, RAG, and tool use, supporting 100+ LLM providers in as few as five lines of code.
Alluxio — Data Orchestration for Analytics and AI
Alluxio is an open-source data orchestration platform that provides a unified data access layer between compute frameworks and storage systems. It caches frequently accessed data closer to compute, accelerating workloads on Spark, Presto, Trino, and AI/ML pipelines.
ParadeDB — Elasticsearch-Quality Search Inside Postgres
ParadeDB is an open-source PostgreSQL extension that brings full-text search, hybrid search, and analytics capabilities directly into Postgres, replacing the need for a separate Elasticsearch cluster.