AI Engineering Elasticsearch & Mistral 9 min read ยท August 10, 2026

Building NYC PULSE with Mistral and Elasticsearch

By Sairam Kumar Reddy Veereddy ยท AI/ML Engineer

"Elastic gives NYC Pulse memory. Mistral gives NYC Pulse reasoning."

In complex urban centers like New York City, a major infrastructure failure is never an isolated event. When the L subway train breaks down at Bedford Avenue during evening rush hour, the immediate problem is strand passengers. But within 15 minutes, secondary ripple effects unfold: tens of thousands of commuters flood street level, ride-share surge pricing skyrockets, the M14 bus is overwhelmed, sidewalk congestion triggers noise complaints, and nearby bodega foot-traffic swings wildly.

Conventional emergency management systems output static alerts. Modern AI attempts typically feed the incident into an LLM with naive RAG: "A train is stalled at Bedford. What happens next?" The LLM hallucinates generalized speculation that cannot be audited or acted upon.

To solve this, I built NYC Pulse: an evidence-driven urban intelligence agent that pairs Mistral Large with an Elasticsearch memory bank using an autonomous Evidence Loop.

Why Standard RAG Fails for Ripple-Effect Modeling

In traditional Retrieval-Augmented Generation (RAG):

Traditional RAG Architecture (Single Pass)
User Query -> Retrieve Vector Docs -> Prompt Context -> Single LLM Output

This single-shot pipeline fails because ripple effects are hypothetical until verified by empirical signals. If the LLM assumes that an outage at Bedford Avenue will cause a surge in 311 noise complaints, but historical Elasticsearch records show that noise complaints in Williamsburg correlate strictly with weekend nightlife rather than transit outages, standard RAG will still state it as fact.

The Core Differentiator: The Two-Phase Evidence Loop

NYC Pulse replaces naive retrieval with an active investigation loop:

NYC Pulse Architecture: The Evidence Loop
flowchart TD
    Event[NYC Urban Event: Subway Failure] --> M1[Mistral Large: Initial Analysis]
    M1 -->|Geo & Schedule Tools| E1[Elasticsearch GTFS & Baseline Indices]
    E1 -.->|Nearby transit stations & baseline complaints| M1
    M1 -->|Formulates Testable Hypotheses| M2[Mistral Hypothesis Engine]
    M2 -->|Evidence Query Tools| E2[Elasticsearch 311 Evidence Verification]
    E2 -.->|Supporting / Contradicting Historical Signals| M2
    M2 --> Final[Structured Ripple-Effect Intelligence Report]
          

How Elasticsearch Powers the Memory

Elasticsearch serves three distinct memory functions in NYC Pulse:

  1. Geographic Transit Awareness: Using geo_distance queries over static GTFS subway schedules to locate all alternate train and bus stops within an 800-meter radius.
  2. Historical 311 Analysis: Full-text BM25 search over millions of historical 311 service requests to find complaints logged during past disruptions.
  3. Statistical Baseline Aggregations: Computing expected complaint rates per neighborhood to separate disruption spikes from normal city background noise.
Python (Elasticsearch Geo-Distance & Aggregation Tool)
def find_alternate_transit(lat: float, lon: float, radius_meters: int = 800):
    """Locate alternate transit stations within radius using geo_distance."""
    query = {
        "bool": {
            "filter": {
                "geo_distance": {
                    "distance": f"{radius_meters}m",
                    "location": {"lat": lat, "lon": lon}
                }
            }
        }
    }
    res = es_client.search(index="mta-gtfs-stops", query=query, size=10)
    return [hit["_source"] for hit in res["hits"]["hits"]]

Mistral Large Function Calling

We selected mistral-large-latest for its deterministic tool execution and strong reasoning over JSON schemas. In our implementation, Mistral is registered with specialized tool primitives:

Python (Mistral Agent Investigation Loop)
messages = [
    {"role": "system", "content": SYSTEM_PROMPT},
    {"role": "user", "content": f"Analyze disruption: {event_description}"}
]

# Turn 1: Mistral autonomously investigates geographic context
response = mistral_client.chat(
    model="mistral-large-latest",
    messages=messages,
    tools=NYC_PULSE_TOOLS,
    tool_choice="auto"
)

# Execute tool calls and feed evidence back into conversation context
if response.choices[0].message.tool_calls:
    for tool_call in response.choices[0].message.tool_calls:
        tool_result = execute_tool(tool_call.function.name, tool_call.function.arguments)
        messages.append({
            "role": "tool",
            "name": tool_call.function.name,
            "content": json.dumps(tool_result),
            "tool_call_id": tool_call.id
        })

# Turn 2: Mistral synthesizes grounded hypotheses and checks contradictory evidence
final_report = mistral_client.chat(
    model="mistral-large-latest",
    messages=messages,
    response_format={"type": "json_object"}
)

Lessons Learned & Future Architecture

The primary engineering lesson from NYC Pulse is that multi-turn evidence verification beats larger context windows. Dumping thousands of 311 rows into a massive prompt confuses the model's causal reasoning. Allowing the model to ask targeted follow-up queries against Elasticsearch produces grounded, hallucination-free outputs that city planners and logistics operators can trust.

View nyc-pulse on GitHub โ†’ Next: How I Built JobNinjas.ai โ†’