TOOL WIKI · AGENT SDKS
Haystack
Builds component-based pipelines for retrieval, generation, and agent applications.
Jump to a section 10 sections
EXAMPLE USE CASE
Retrieve the correct store’s return policy
A developer needs a small, observable agent or retrieval step before connecting real business services.
- Input
- Three policy/shipping documents, query returns and a tenant filter.
- Expected output
- The 30-day tenant-a document rather than tenant-b’s 90-day policy.
- Success check: The first document describes the 30-day policy and belongs to tenant a.
- Try a failure: Remove the tenant filter and see why relevance is not an access-control rule.
Example scope: Runnable BM25 retriever baseline; no generation model or agent loop.
Authenticate the request and define the goal before calling the framework.
taskTo 02 · HaystackA system that benefits from explicit data-processing components. Measure each pipeline stage using representative source documents.
invokeTo 03 · Model providertool callTo 04 · Tool servicemeasureTo 06 · EvaluationThe application supplies provider credentials, model selection, and budgets.
decisionBack to 02 · HaystackValidate each operation and return authoritative observations.
resultBack to 02 · HaystackChoose the checkpoint or session store and its retention policy deliberately.
Result or stopping pointCheck completion, cost, latency, and tool behavior against fixtures.
Result or stopping point
A system that benefits from explicit data-processing components. Measure each pipeline stage using representative source documents.
When to consider it
- A system that benefits from explicit data-processing components.
A design decision to make
- Measure each pipeline stage using representative source documents.
Prerequisites and setup
- Python 3.11+. This retrieval component example does not need a model or API key.
python3 -m venv .venv
source .venv/bin/activate
pip install haystack-aiTry a small integration
example.py
from haystack import Document
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
store = InMemoryDocumentStore()
store.write_documents([
Document(content="Returns are accepted within 30 days.", meta={"tenant":"a"}),
Document(content="Shipping normally takes 5 days.", meta={"tenant":"a"}),
Document(content="Returns are accepted within 90 days.", meta={"tenant":"b"}),
])
retriever = InMemoryBM25Retriever(document_store=store)
result = retriever.run(query="returns", top_k=1,
filters={"field":"meta.tenant", "operator":"==", "value":"a"})
print(result["documents"][0].content)
assert result["documents"][0].meta["tenant"] == "a"Run and check the result
python example.py- The first document describes the 30-day policy and belongs to tenant a.
- A BM25 retriever ranks text; attach a generator and evaluate grounded answers as a separate pipeline step.
Common failures
- Do not install the unrelated legacy haystack package in place of haystack-ai.
- A missing filter can retrieve another tenant. Enforce scope in application code, not in the question.
Production decisions
- Bind tool execution to the authenticated user and resource permissions. Keep keys in server environment variables.
- Add deadlines, a turn budget, redacted traces, regression fixtures and explicit handling for refused or incomplete runs.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.