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):
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:
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:
- Geographic Transit Awareness: Using
geo_distancequeries over static GTFS subway schedules to locate all alternate train and bus stops within an 800-meter radius. - Historical 311 Analysis: Full-text BM25 search over millions of historical 311 service requests to find complaints logged during past disruptions.
- Statistical Baseline Aggregations: Computing expected complaint rates per neighborhood to separate disruption spikes from normal city background noise.
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:
search_311_complaints(descriptor, neighborhood, time_range)find_nearby_stops(station_name, radius_meters)get_neighborhood_baseline(borough, complaint_type)verify_causal_hypothesis(hypothesis_statement, required_signal)
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.