How to Integrate Haystack for wealth management with Elasticsearch for multi-agent systems

By Cyprian AaronsUpdated 2026-04-21
haystack-for-wealth-managementelasticsearchmulti-agent-systems

Haystack for wealth management gives you the retrieval and orchestration layer for portfolio, client, and market intelligence workflows. Elasticsearch gives you fast, scalable indexing and filtering across documents, notes, filings, and conversation history. Put them together in a multi-agent system and you get agents that can retrieve the right wealth data, rank it with context, and act on it without brittle prompt stuffing.

Prerequisites

  • Python 3.10+
  • An Elasticsearch cluster running locally or in your VPC
  • Access to your Haystack for wealth management package and credentials
  • pip installed
  • Environment variables set for:
    • ELASTICSEARCH_URL
    • ELASTICSEARCH_API_KEY or username/password
    • Any Haystack-specific API key or endpoint required by your deployment
  • A document set ready to index:
    • client notes
    • portfolio commentary
    • research summaries
    • compliance memos

Integration Steps

  1. Install the dependencies.
pip install haystack-ai elasticsearch python-dotenv

If your wealth-management setup uses a custom Haystack package, install that too. In most production systems I see this wrapped behind an internal SDK or service endpoint.

  1. Connect to Elasticsearch and create an index for agent memory.

Use a dedicated index for wealth-management retrieval. Keep it separate from raw logs so you can control retention and access policies.

from elasticsearch import Elasticsearch

es = Elasticsearch(
    "https://localhost:9200",
    api_key="YOUR_ELASTIC_API_KEY",
)

index_name = "wealth-agent-memory"

if not es.indices.exists(index=index_name):
    es.indices.create(
        index=index_name,
        mappings={
            "properties": {
                "client_id": {"type": "keyword"},
                "doc_type": {"type": "keyword"},
                "content": {"type": "text"},
                "created_at": {"type": "date"},
            }
        },
    )

print(es.info())
  1. Build a Haystack pipeline that retrieves from Elasticsearch.

Haystack’s ElasticsearchDocumentStore is the cleanest way to wire search into pipelines. If you are using Haystack in a wealth-management agent stack, this becomes the retrieval layer for portfolio context, meeting notes, and policy documents.

from haystack import Document, Pipeline
from haystack.document_stores.elasticsearch import ElasticsearchDocumentStore
from haystack.components.retrievers import InMemoryBM25Retriever

document_store = ElasticsearchDocumentStore(
    hosts=["https://localhost:9200"],
    index="wealth-agent-memory",
    basic_auth=("elastic", "YOUR_PASSWORD"),
    embedding_dim=384,
)

docs = [
    Document(content="Client A has moderate risk tolerance and prefers dividend income.", meta={"client_id": "client-a", "doc_type": "profile"}),
    Document(content="Portfolio review flagged overweight exposure to financials.", meta={"client_id": "client-a", "doc_type": "review"}),
]

document_store.write_documents(docs)

For a pure search-backed workflow, you can also use Elasticsearch directly as your retriever source:

from haystack.components.retrievers import ElasticsearchBM25Retriever

retriever = ElasticsearchBM25Retriever(document_store=document_store)

query = "What is client A's risk profile?"
results = retriever.run(query=query)

for doc in results["documents"]:
    print(doc.content, doc.meta)
  1. Add an agent orchestration layer for multi-agent systems.

In a multi-agent setup, one agent can handle retrieval while another handles reasoning or compliance checks. The key is that both agents share the same indexed truth source in Elasticsearch.

from haystack.components.builders import PromptBuilder
from haystack.components.generators import OpenAIGenerator

prompt_template = """
You are a wealth management assistant.
Use only the retrieved context below.

Context:
{% for doc in documents %}
- {{ doc.content }}
{% endfor %}

Question: {{ question }}
Answer concisely.
"""

prompt_builder = PromptBuilder(template=prompt_template)
llm = OpenAIGenerator(model="gpt-4o-mini", api_key="YOUR_OPENAI_API_KEY")

pipeline = Pipeline()
pipeline.add_component("retriever", retriever)
pipeline.add_component("prompt_builder", prompt_builder)
pipeline.add_component("llm", llm)

pipeline.connect("retriever.documents", "prompt_builder.documents")
pipeline.connect("prompt_builder.prompt", "llm.prompt")

response = pipeline.run({
    "retriever": {"query": "Summarize client A's portfolio concerns."},
    "prompt_builder": {"question": "Summarize client A's portfolio concerns."},
})

print(response["llm"]["replies"][0])
  1. Write agent memory back to Elasticsearch after each interaction.

This is what makes the system useful across multiple agents. Retrieval gets better over time because each interaction becomes searchable state.

from datetime import datetime

interaction = {
    "client_id": "client-a",
    "doc_type": "agent_note",
    "content": "Agent recommended reducing financial sector exposure by 5%.",
    "created_at": datetime.utcnow(),
}

es.index(index=index_name, document=interaction)
es.indices.refresh(index=index_name)

search_result = es.search(
    index=index_name,
    query={
        "bool": {
            "must": [
                {"match": {"content": "financial sector exposure"}},
                {"term": {"client_id": "client-a"}}
            ]
        }
    },
)

print(search_result["hits"]["hits"][0]["_source"])

Testing the Integration

Run a simple end-to-end check: write a document to Elasticsearch, retrieve it through Haystack, and confirm the response contains the expected context.

test_doc = Document(
    content="Client B has a long-term horizon and low turnover preference.",
    meta={"client_id": "client-b", "doc_type": "profile"},
)

document_store.write_documents([test_doc])

result = retriever.run(query="What is client B's investment horizon?")
docs = result["documents"]

print(docs[0].content)

Expected output:

Client B has a long-term horizon and low turnover preference.

If that returns cleanly, your Haystack retrieval path and Elasticsearch storage path are connected correctly.

Real-World Use Cases

  • Advisor copilot
    • Retrieve client profiles, recent meeting notes, and portfolio changes before generating advisor responses.
  • Compliance-aware multi-agent review
    • One agent drafts recommendations while another checks stored policy docs and prior decisions in Elasticsearch.
  • Relationship manager search
    • Index emails, call summaries, and research notes so agents can answer account-specific questions with traceable evidence.

Keep learning

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

Related Guides