How to Integrate Haystack for wealth management with Elasticsearch for production AI
Combining Haystack for wealth management with Elasticsearch gives you a clean path from unstructured financial documents to retrieval-backed AI workflows. The practical win is simple: your agent can search market reports, client notes, policy docs, and research archives with low latency, then use that context to answer questions or trigger downstream actions.
Prerequisites
- •Python 3.10+
- •An Elasticsearch cluster running locally or in production
- •A Haystack environment configured for your wealth management use case
- •API credentials or network access to your Elasticsearch cluster
- •
pipinstalled - •Familiarity with document ingestion, embeddings, and retrieval pipelines
Install the core packages:
pip install haystack-ai elasticsearch sentence-transformers
If you’re using a managed Elasticsearch deployment, make sure you have:
- •Host URL
- •Username/password or API key
- •TLS settings if required
Integration Steps
- •Connect to Elasticsearch
Start by creating an Elasticsearch client. In production, use API keys instead of hardcoded passwords.
from elasticsearch import Elasticsearch
es = Elasticsearch(
"https://localhost:9200",
api_key=("your_api_key_id", "your_api_key_secret"),
verify_certs=True,
)
print(es.info())
This confirms the cluster is reachable before you wire it into Haystack.
- •Create a Haystack document store backed by Elasticsearch
Haystack uses a document store abstraction so your agent can write and retrieve content without caring about storage details.
from haystack.document_stores.elasticsearch import ElasticsearchDocumentStore
document_store = ElasticsearchDocumentStore(
hosts=["https://localhost:9200"],
index="wealth-management-docs",
embedding_dim=384,
similarity="cosine",
api_key=("your_api_key_id", "your_api_key_secret"),
verify_certs=True,
)
print(document_store.count_documents())
This gives you a persistent index for client statements, research notes, suitability docs, and internal memos.
- •Write financial documents into the store
For wealth management workflows, your source data is usually PDFs, CRM exports, or compliance notes. Convert them into Haystack Document objects before writing them.
from haystack import Document
docs = [
Document(
content="Client prefers moderate risk portfolio with 60/40 allocation and ESG constraints.",
meta={"client_id": "C1024", "doc_type": "advisory_note"}
),
Document(
content="Q4 macro outlook suggests lower duration exposure due to rate volatility.",
meta={"doc_type": "research_note"}
),
]
document_store.write_documents(docs)
print("Documents written:", document_store.count_documents())
If you already have parsed text from ingestion pipelines, this is the point where it enters retrieval.
- •Build a retrieval pipeline in Haystack
Use an embedding retriever so your agent can find relevant context from Elasticsearch before generating an answer.
from haystack.nodes import EmbeddingRetriever
retriever = EmbeddingRetriever(
document_store=document_store,
embedding_model="sentence-transformers/all-MiniLM-L6-v2",
model_format="sentence_transformers"
)
document_store.update_embeddings(retriever)
results = retriever.retrieve("What is the client's preferred risk profile?")
for doc in results[:3]:
print(doc.content, doc.meta)
The key production pattern here is indexing embeddings once, then retrieving quickly at query time.
- •Use retrieved context inside your agent logic
Once retrieval works, wrap it in your agent flow. Your LLM layer can now answer from indexed wealth-management knowledge instead of guessing.
query = "What portfolio allocation should we recommend for this client?"
retrieved_docs = retriever.retrieve(query)
context = "\n\n".join([doc.content for doc in retrieved_docs[:5]])
prompt = f"""
You are a wealth management assistant.
Use the context below to answer the question.
Context:
{context}
Question:
{query}
"""
print(prompt)
In production, this prompt would go to your model endpoint after adding guardrails for compliance and suitability checks.
Testing the Integration
Run a basic end-to-end verification: write a document, retrieve it by query, and confirm the expected note comes back.
test_query = "What risk profile does the client prefer?"
hits = retriever.retrieve(test_query)
assert len(hits) > 0
assert any("moderate risk portfolio" in doc.content for doc in hits)
for doc in hits[:1]:
print("Top hit:", doc.content)
print("Metadata:", doc.meta)
Expected output:
Top hit: Client prefers moderate risk portfolio with 60/40 allocation and ESG constraints.
Metadata: {'client_id': 'C1024', 'doc_type': 'advisory_note'}
If that passes, your Haystack-to-Elasticsearch path is working end to end.
Real-World Use Cases
- •
Advisor copilots
- •Retrieve prior meeting notes, portfolio preferences, and research snippets before drafting client recommendations.
- •
Compliance-aware search
- •Index policy manuals and suitability rules so agents can surface approved guidance during advisor interactions.
- •
Client intelligence workflows
- •Search CRM notes and market commentary together to generate personalized outreach or portfolio review summaries.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit