Haystack — Production RAG & Agent Framework
Build composable AI pipelines for RAG, agents, and search. Model-agnostic, production-ready, by deepset. 18K+ stars.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 2126f372-519e-45bd-8817-69d70e061bb0 --target codex先 dry-run 确认安装计划,再运行此命令。
What it is
Haystack is an open-source framework by deepset for building composable AI pipelines. It supports retrieval-augmented generation (RAG), document search, conversational agents, and custom NLP workflows. Haystack is model-agnostic, working with OpenAI, Anthropic, Cohere, Hugging Face, and local models.
It targets AI engineers and product teams building search, Q&A, or agent systems that need to connect retrievers, generators, and tools into production-ready pipelines.
How it saves time or tokens
Haystack's component-based architecture lets you swap models, retrievers, and stores without rewriting pipeline logic. The built-in evaluation tools measure retrieval quality and generation accuracy so you can optimize before shipping. Pipeline YAML serialization means you can version-control and deploy pipeline configurations without code changes. The estimated token usage per pipeline run is around 897 tokens depending on document length.
How to use
- Install Haystack:
pip install haystack-ai
- Build a simple RAG pipeline:
from haystack import Pipeline
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder
template = '''Answer the question based on the context.
Context: {{context}}
Question: {{question}}'''
pipe = Pipeline()
pipe.add_component('prompt', PromptBuilder(template=template))
pipe.add_component('llm', OpenAIGenerator(model='gpt-4o'))
pipe.connect('prompt', 'llm')
result = pipe.run({
'prompt': {
'context': 'Haystack is an AI framework by deepset.',
'question': 'Who built Haystack?'
}
})
print(result['llm']['replies'][0])
- Add a retriever for document-based RAG:
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
store = InMemoryDocumentStore()
retriever = InMemoryBM25Retriever(document_store=store)
Example
A complete indexing and query pipeline:
from haystack import Document
docs = [
Document(content='Haystack supports RAG pipelines.'),
Document(content='Deepset is based in Berlin.'),
]
store.write_documents(docs)
results = retriever.run(query='What does Haystack support?')
for doc in results['documents']:
print(doc.content)
Related on TokRepo
- RAG tools — retrieval-augmented generation frameworks and utilities
- AI agent tools — agent frameworks for building autonomous systems
Common pitfalls
- Using InMemoryDocumentStore in production fails under load. Switch to Elasticsearch, Weaviate, or Qdrant for persistent, scalable storage.
- Forgetting to set the OPENAI_API_KEY environment variable causes silent failures. Haystack does not always surface clear error messages for missing credentials.
- Pipeline connections must match component input/output names exactly. A typo in connect() calls produces runtime errors, not compile-time warnings.
常见问题
Haystack focuses on pipeline-based composition with typed inputs and outputs, making it easier to test and debug individual components. LangChain uses a chain abstraction with more flexibility but less structure. Haystack has stronger built-in evaluation tools.
Haystack supports Elasticsearch, OpenSearch, Weaviate, Qdrant, Pinecone, Chroma, pgvector, and an in-memory store. Each has a dedicated DocumentStore integration package.
Yes. Haystack integrates with Hugging Face Transformers, Ollama, and vLLM for local inference. Use the corresponding generator component instead of OpenAIGenerator.
Yes. Generator components support streaming callbacks. You can stream tokens to your frontend as they are generated, reducing perceived latency for users.
Yes. Haystack is used in production by enterprises for document search, customer support automation, and internal knowledge bases. Version 2.x introduced a more stable API with better type safety and component validation.
引用来源 (3)
- Haystack GitHub— Haystack is an open-source AI framework by deepset for composable pipelines
- Haystack Documentation— Supports RAG, document search, and agent workflows with multiple model providers
- Haystack Concepts— Component-based pipeline architecture with typed inputs and outputs
来源与感谢
- GitHub: deepset-ai/haystack
- License: Apache 2.0
- Stars: 18,000+
- Maintainer: deepset GmbH
Thanks to the deepset team for building the most production-oriented RAG framework, proving that AI pipelines can be both composable and reliable enough for enterprise deployment.
讨论
相关资产
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.
ZenML — MLOps Pipeline Framework from Development to Production
An open-source MLOps framework that lets you build portable, production-ready ML pipelines that run on any infrastructure stack.
Pydantic AI — Production AI Agent Framework
Build production-ready AI agents in Python with type-safe structured outputs, dependency injection, and multi-model support. By the creators of Pydantic.
Kedro — Production-Ready ML Pipeline Framework for Python
Kedro is an open-source Python framework by McKinsey QuantumBlack that applies software engineering best practices to data science and ML pipelines. It provides a standardized project structure, data catalog, and pipeline abstraction that makes experimental code production-ready.