The AI Product Research Assistant is a modular, containerized application that combines RAG (Retrieval Augmented Generation), web search, and deterministic price analysis to help product teams make data-driven decisions.
1. User submits query via POST /query
↓
2. FastAPI validates request
↓
3. LangGraph agent receives query
↓
4. Agent analyzes query intent
↓
5. Agent selects appropriate tool(s)
↓
6. Tool(s) execute:
- Product RAG → Qdrant search
- Web Search → External API/Mock
- Price Analysis → Deterministic calc
↓
7. Results returned to agent
↓
8. Agent generates final response
↓
9. Response saved to SQLite
↓
10. Response returned to user
1. CSV file loaded (products_catalog.csv)
↓
2. Text prepared for embedding
(name + brand + category + description)
↓
3. Embeddings generated
(Sentence Transformers)
↓
4. Points upserted to Qdrant
(ID from product_id for updates)
↓
5. Payload indexes created
(category, brand, price, etc.)
The system handles monthly catalog updates efficiently:
-
Upsert Pattern: Products are upserted by
product_id- New products are added
- Existing products are updated
- No full re-indexing required
-
Change Detection:
# Product ID is converted to numeric point ID # Same product_id always maps to same point_id point_id = hash(product_id) % (2**63) # Upsert handles both insert and update client.upsert(collection_name, points)
-
Update Process:
# Run ingestion with new CSV python -m src.ingestion.pipeline --csv new_catalog.csv # Or via API (future enhancement) POST /admin/ingest
| Update Type | Frequency | Method |
|---|---|---|
| Full catalog refresh | Monthly | Full ingestion |
| Price updates | Weekly | Partial upsert |
| New products | As needed | Incremental add |
| Removed products | Monthly | Mark as deleted |
- Handles 1-5 requests/second
- Suitable for development and small teams
- All services on single machine
For higher load:
┌──────────────┐
│ Load Balancer│
└──────┬───────┘
│
┌────────────────┼────────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ App 1 │ │ App 2 │ │ App 3 │
└────┬─────┘ └────┬─────┘ └────┬─────┘
│ │ │
└───────────────┼───────────────┘
▼
┌─────────────────────┐
│ Shared Services │
│ │
│ - Qdrant Cluster │
│ - PostgreSQL │
│ - Ollama Pool │
│ - Redis Cache │
└─────────────────────┘
- API Layer: Horizontal scaling with load balancer
- Qdrant: Cluster mode for larger datasets
- Ollama: Multiple instances with request routing
- Database: PostgreSQL for production
- Caching: Redis for frequent queries
| Component | Typical Latency |
|---|---|
| Vector search | 10-50ms |
| LLM inference | 2-10 seconds |
| Web search | 200-500ms |
| Database | 1-10ms |
You can see that LLM inference is took the longest time, so we need to optimize it.
Optimization strategies:
- Response caching for common queries
- Streaming responses
- Async processing for non-critical paths
| Component | Cost Type |
|---|---|
| Ollama | Infrastructure (CPU/GPU) |
| Qdrant | Infrastructure + Storage |
| Web Search API | Per-request (if using real API) |
| Embedding Model | One-time download |
Cost optimization:
- Use smaller models for simple queries (or using API provider)
- Cache embeddings and responses
- Batch similar queries
-
API Security:
- Rate limiting
- API key authentication
- Input validation
-
Data Security:
- No sensitive data in logs
- Encrypted storage
- Secure environment variables
-
Network Security:
- Internal service communication only
- HTTPS in production
- Firewall rules
Pros:
- No API costs
- Data stays local
- No rate limits
- Full control
Cons:
- Higher infrastructure requirements
- Slower than cloud APIs
- Limited to local hardware
Pros:
- Faster responses
- Better model quality
- No infrastructure management
Cons:
- Per-request costs
- Data leaves your infrastructure !!
- Rate limits and quotas
Why Qdrant:
- Easy Docker deployment
- Good filtering support
- Active development
- Free and open source
Alternatives considered:
- Pinecone: Better scalability but paid
- Weaviate: More features but heavier
- Chroma: Simpler but less production-ready
┌────────────────────────────────────────────────┐
│ Grafana │
│ (Dashboards & Alerting) │
└─────────────────────┬──────────────────────────┘
│
┌─────────────┼─────────────┐
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│Prometheus │ │ Loki │ │ Jaeger │
│ (Metrics) │ │ (Logs) │ │ (Traces) │
└───────────┘ └───────────┘ └───────────┘
- Request latency (p50, p95, p99)
- Error rate
- Tool usage distribution
- LLM token usage
- Vector search latency
- Memory and CPU usage
- What did they think?
- Caching Layer: Redis for response caching
- Admin Dashboard: UI for monitoring and management
- A/B Testing: Compare different models/prompts
- Real-time Updates: WebSocket for live catalog changes
- Advanced Analytics: Query pattern analysis