AI-powered conversational isochrone mapping application that combines natural language queries with real-time map visualizations. Ask questions like "coffee shops I can bike to in 15 minutes" and get instant visual results with AI explanations.
git clone https://github.com/yourusername/ChatMap.git
cd ChatMap/chatmap
./setup-local.sh # Automated setup with Ollama + Qdrant
npm run dev # Runs on http://localhost:3000Prerequisites:
- Node.js 18+
- Docker & Docker Compose (for Qdrant vector database)
- Ollama (for local LLM)
- Valid OpenRouteService API key
The setup-local.sh script handles everything:
./setup-local.shThis will:
- β Check prerequisites (Node.js, Docker, Ollama)
- β Start Qdrant vector database
- β Download AI models (llama3.2:3b, nomic-embed-text)
- β Install npm dependencies
- β
Create
.env.localwith your API key - β Verify all services are running
# 1. Start Qdrant vector database
docker-compose up -d
# 2. Install Ollama models
ollama pull llama3.2:3b # Main chat model (~2GB)
ollama pull nomic-embed-text # Embeddings (~274MB)
# 3. Install dependencies
npm install
# 4. Configure environment
cp .env.example .env.local
# Edit .env.local with your OpenRouteService API key- Natural Language Understanding: Parse complex location queries with AI agents
- Query Classification: Automatic intent detection (find-nearest, find-within-time, find-near-poi, find-enroute)
- Multi-Step Reasoning: Complex queries decomposed into coordinated steps
- Contextual Follow-ups: "how about drive then?" maintains previous query context
- 4 Query Types Supported:
- Find nearest X β "Find nearest cafe"
- Find X within Y minutes β "Find restaurants within 15 min walk"
- Find X near nearest Y β "Find coffee shops near the nearest park"
- Find X enroute to Y β "Find gas station before airport in 30 mins"
- Agent Metadata Display: See how the AI classifies and processes queries
- Execution Metrics: Response time, API call count, confidence scores
- Reasoning Steps: Step-by-step logic visualization
- Tool Usage: Track which tools the agent uses
- Isochrone Generation: Real-time reachability analysis
- Route Optimization: Find optimal stopovers along routes
- Multi-Modal Transport: Walking, driving, cycling, public transport
- POI Filtering: Polygon-based spatial filtering with Turf.js
- Semantic Memory: Vector-based memory storage with Qdrant
- User Preferences: Learns favorite transport modes, POI types, cuisines
- Conversation History: Remembers past interactions and context
- Location Patterns: Tracks frequently visited places and times
- Smart Recommendations: Personalized suggestions based on history
- Multi-turn Context: Maintains conversation state across sessions
flowchart TB
U[User Query]
QA[Query Analyzer]
C{Complex?}
DQ[Query Decomposer]
SQ[Single Query Flow]
S1[Geocode<br/>/api/geocode -> Nominatim]
S2[Isochrone<br/>/api/isochrone -> OpenRouteService]
S3[POIs<br/>/api/pois -> Overpass]
AGG[Aggregator]
NORM[Normalize & Shape<br/>GeoJSON + markers]
LLM[Ollama Chat<br/>Streaming]
MEM[Memory Context<br/>mem0ai + Qdrant]
VERIFY[Optional Claim Verification<br/>confidence + conflicts]
RT[Real-time Token Stream]
MAP[Map Render<br/>Leaflet]
UI[Client UI]
U --> QA --> C
C -->|Yes| DQ
C -->|No| SQ
DQ --> S1
DQ --> S2
DQ --> S3
SQ --> AGG
S1 --> AGG
S2 --> AGG
S3 --> AGG
AGG --> NORM --> LLM
QA -. fetch context .-> MEM
MEM -. enrich .-> LLM
LLM --> RT --> UI
NORM --> MAP --> UI
LLM --> VERIFY --> UI
- Clean Architecture: Routes validate, use cases contain logic, clients handle APIs
- Separation of Concerns: Clear boundaries between layers
- Type Safety: Full TypeScript coverage with Zod validation
- Error Handling: Structured error codes with retry logic
- Observability: Execution metrics, API call tracking, warnings
POST /api/agent
Content-Type: application/json
{
"query": "Find coffee shops within 15 minutes walk",
"userId": "user123",
"userLocation": {
"lat": 51.5074,
"lng": -0.1278,
"display_name": "London"
},
"memoryEnabled": true
}Response:
{
"success": true,
"data": {
"classification": {
"intent": "find-within-time",
"complexity": "simple",
"confidence": 0.95,
"entities": {
"primaryPOI": "cafe",
"timeConstraint": 15,
"transport": "walking"
}
},
"agentUsed": "SimpleQueryAgent",
"result": {
"success": true,
"data": {
"pois": [...],
"count": 25,
"isochrone": {...}
},
"toolsUsed": ["find_pois_within_time"],
"reasoningSteps": [...]
}
}
}| Endpoint | Purpose | Complexity |
|---|---|---|
POST /api/agent |
Intelligent query routing | Variable |
POST /api/pois |
Find POIs within time | Simple (2 API calls) |
POST /api/poi/nearest |
Find nearest POI | Simple (2 API calls) |
POST /api/poi/near-poi |
Find X near nearest Y | Complex (4 API calls) |
POST /api/poi/enroute |
Find POI along route | Complex (5-7 API calls) |
POST /api/geocode |
Address to coordinates | Simple (1 API call) |
POST /api/directions |
Calculate route | Simple (1 API call) |
POST /api/memory |
Store memory | 1 API call + embedding |
GET /api/memory |
Search/list memories | Vector search |
GET /api/memory/context |
Get user context | Aggregation |
# Intelligent Agent Query (Recommended)
curl -X POST http://localhost:3000/api/agent \
-H "Content-Type: application/json" \
-d '{
"query": "Find restaurants within 15 minutes walk",
"userId": "user123",
"userLocation": {"lat": 51.5074, "lng": -0.1278, "display_name": "London"},
"memoryEnabled": true
}'
# Store User Preference
curl -X POST http://localhost:3000/api/memory \
-H "Content-Type: application/json" \
-d '{
"userId": "user123",
"content": "User prefers Italian restaurants and walking over driving",
"type": "preference",
"metadata": {"cuisine": "italian", "transport": "walking"}
}'
# Search Memories Semantically
curl "http://localhost:3000/api/memory?userId=user123&query=food%20preferences"
# Get User Context
curl "http://localhost:3000/api/memory/context?userId=user123"- Next.js 15.5 - React framework with Turbopack
- TypeScript 5.0 - Type-safe development
- Tailwind CSS - Utility-first styling
- Leaflet - Interactive maps
- Lucide React - Beautiful icons
- Next.js API Routes - Serverless endpoints
- LangChain - Agent orchestration & tool execution
- Ollama - Local LLM inference (zero-cost)
- Zod - Runtime type validation
- OpenRouteService - Routing, isochrones, optimization
- Nominatim - Geocoding (OSM)
- Overpass API - POI discovery (OSM)
- Turf.js - Geospatial analysis
- llama3.2:3b - Query classification & response generation (~2GB)
- nomic-embed-text - 768-dim embeddings for semantic search (~274MB)
- Qdrant - High-performance vector database
- Mem0-style Architecture - Intelligent user memory system
- Semantic similarity search
- Automatic context aggregation
- User preference learning
- Conversation history tracking
chatmap/
βββ src/
β βββ app/
β β βββ api/ # API route handlers
β β β βββ agent/ # Intelligent agent endpoint
β β β βββ pois/ # POI search
β β β βββ poi/
β β β β βββ nearest/ # Find nearest POI
β β β β βββ near-poi/ # Complex multi-step
β β β β βββ enroute/ # Route optimization
β β β βββ geocode/ # Address β coordinates
β β β βββ directions/ # Routing
β β β βββ memory/ # User memory
β β βββ layout.tsx
β β βββ page.tsx # Main application
β βββ components/
β β βββ Chat.tsx # Chat interface
β β βββ Map.tsx # Leaflet map
β β βββ AgentMetadata.tsx # Agent reasoning display
β β βββ QueryInput.tsx # Search input
β βββ agents/
β β βββ query-classifier.ts # LLM-based classification
β β βββ simple-query-agent.ts # Single-step queries
β β βββ multi-step-query-agent.ts # Complex queries
β β βββ agent-orchestrator.ts # Agent routing
β β βββ tools/index.ts # LangChain tools
β β βββ prompts/ # Prompt templates
β βββ usecases/
β β βββ find-nearest-poi.ts # Business logic
β β βββ find-pois-within-time.ts
β β βββ find-pois-near-poi.ts
β β βββ find-poi-enroute.ts
β β βββ types.ts # Use case types
β βββ clients/
β β βββ ors-client.ts # OpenRouteService
β β βββ nominatim-client.ts # Geocoding
β β βββ overpass-client.ts # POI search
β β βββ ollama-client.ts # LLM
β β βββ memory-client.ts # Memory system
β βββ lib/
β βββ types.ts # Core types
β βββ config.ts # Configuration
β βββ retry.ts # Retry logic
β βββ rate-limiter.ts # Rate limiting
β βββ agent-api.ts # Agent API client
βββ public/ # Static assets
βββ e2e/ # End-to-end tests
βββ .env.local # Environment config
βββ package.json
βββ tsconfig.json
βββ README.md
curl http://localhost:3000/api/agent
# Should return: {"status":"healthy","data":{...}}Simple Query:
"Find restaurants within 15 minutes walk"
β SimpleQueryAgent β 2 API calls β ~2-4s
Complex Query:
"Find coffee shops near the nearest park"
β MultiStepQueryAgent β 4 API calls β ~5-7s
β Steps:
1. Find nearest park
2. Search cafes near park
3. Calculate travel times
4. Sort by distance
Route Optimization:
"Find gas station before airport in 30 mins"
β MultiStepQueryAgent β 5-7 API calls β ~8-12s
β Steps:
1. Geocode destination
2. Calculate direct route
3. Find POIs along route
4. Optimize stopover
5. Return best route
Memory Performance:
- β Vector embeddings cached by Ollama
- β Qdrant provides sub-100ms vector search
- β Memory failures don't block main flow
- β Automatic retry with exponential backoff
Optimization Opportunities:
- Response caching for common queries
- Parallel API call execution
- Progressive result streaming
- Pre-computed isochrones
- Memory batch operations
Contributions welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - Build amazing location-based AI applications!
- OpenRouteService - Routing and isochrone APIs
- OpenStreetMap - POI data via Nominatim & Overpass
- Ollama - Local LLM inference
- LangChain - Agent orchestration framework
- Qdrant - Vector database for memory
- Leaflet - Interactive mapping library
For issues, questions, or feature requests, please open an issue on GitHub.
Built with β€οΈ for intelligent location discovery.