โš™๏ธ Technical Overview

How SmartMovieSearch works

A production multi-agent AI system combining real-time movie data, vector search, and web retrieval into a single streaming answer.

smartmoviesearch.com ยท github.com/worldwidejimmy/pipeline ยท LangGraph ยท Milvus ยท Claude ยท React

01 The Problem

Ask a movie database "Show me good bank heist movies" and it returns nothing โ€” heist is a theme, not a genre tag. Ask it "Is Project Hail Mary Ryan Gosling's best work?" and it has no way to answer. These questions require reasoning, not filtering.

Movie databases like TMDB are exhaustive but rigid. They expose genre filters, release years, and ratings โ€” but they cannot interpret themes, compare filmographies, or synthesise critical perspective. A single LLM call lacks live data. A single API lacks semantic understanding. The only viable solution is decomposition: multiple specialised agents working in parallel, coordinated by an orchestrator.

02 System Architecture

User (browser)
    โ”‚  HTTPS โ€” CDN + TLS termination
    โ”‚
Nginx  (reverse proxy, cloud VPS)
    โ”œโ”€โ”€ /         โ†’ React frontend  (static, port 5174)
    โ””โ”€โ”€ /api/*    โ†’ FastAPI backend (uvicorn,  port 8001)
                      โ”‚
                      โ”‚  Server-Sent Events stream
                      โ”‚
              LangGraph StateGraph
                      โ”‚
               understand          โ† rewrites a follow-up as a standalone question
                      โ”‚
               kb_lookup           โ† knowledge base first: calibrated relevance gate
                      โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚    supervisor_route    โ”‚  โ† decides which agents to invoke
          โ””โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜  (RAG joins if the KB is relevant, skipped if not)
             โ”‚          โ”‚      โ”‚     (parallel fan-out; + music_agent โ†’ MusicBrainz)
       tmdb_agent   rag_agent   search_agent
       TMDB API      KB passages Tavily Web
       (httpx)       :19530      API
             โ”‚          โ”‚      โ”‚
          โ””โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”˜
                      โ”‚
               synthesise          โ† merges results, streams answer
                      โ”‚
             SSE โ†’ browser (token by token)

Each layer has a single, clear responsibility. The understand step makes a follow-up self-contained. The knowledge-base lookup checks the curated corpus first. The supervisor decides routing. Agents specialise. The synthesiser integrates. The SSE stream makes the entire process visible to the user in real time.

03 Core Technologies

LangGraph โ€” Multi-Agent Orchestration

LangGraph models the AI pipeline as a directed graph. Each node is an async Python function (an agent); each edge is conditional routing logic. A shared StateGraph object carries conversation state between nodes, and MemorySaver checkpoints that state (in memory) so multi-turn conversation context persists across queries on the same thread. A follow-up such as "Who composed its score?" is rewritten into a standalone question ("Who composed the score for Inception (2010)?") by one small Claude call before any agent sees it; the final answer still sees the user's own words and the history.

Why not a single LLM call? A prompt cannot simultaneously call a live API, query a vector database, and do a web search. Agents decompose the problem so each specialist uses the right tool โ€” and they run in parallel, not sequentially.

Milvus โ€” Hybrid Vector Search

Milvus stores the movie knowledge corpus (critical essays, directorial analyses, genre guides). The RAG agent retrieves relevant passages using hybrid search: a fusion of two complementary retrieval methods ranked by Reciprocal Rank Fusion (RRF).

Dense
Embedding search
OpenAI text-embedding-3-small converts text to 1536-dim vectors. Finds semantically similar content even when exact words differ.
Sparse
BM25 keyword search
Exact keyword matching โ€” critical for proper nouns, film titles, and director names that embeddings can miss.
Fusion
Weighted fusion
Normalises both lists' scores and adds them, dense 0.7 and BM25 0.3: the precision of BM25 and the recall of embeddings in one ranking. It replaced rank-only RRF after measuring better on the retrieval evals.
Knowledge base first. Every question searches the knowledge base before routing. Retrieval always returns its nearest passages, so a gate decides whether they are useful โ€” on the best dense cosine similarity, because the fused score is relative to the other results. Calibrated on 68 labelled questions: โ‰ฅ 0.60 is relevant (zero false "relevant" on tuning and held-out splits), < 0.45 is nothing useful, neither needing an LLM call; in between, a small Haiku grader decides (17/18 correct on that band). Relevant โ†’ the RAG agent joins and reuses the passages; not โ†’ it is skipped, saving its LLM call.

Anthropic Claude โ€” LLM Inference

Every LLM call โ€” follow-up rewriting, the knowledge-base grader, routing, per-agent intent extraction and final synthesis โ€” goes through a single factory, llm.py:get_chat(). The model is one server-wide cost tier (DEFAULT_MODEL_TIER: haiku ยท sonnet ยท opus, default haiku) that runs the newest model in that tier once it has passed the evals (quality against the baseline, and no rise in cost per question); until then the previous model stays live. Streaming the answer token by token is what makes the UI feel instant.

FastAPI + Server-Sent Events

The backend exposes a single streaming endpoint. It runs the LangGraph pipeline with astream_events() and translates internal events โ€” agent lifecycle, LLM tokens, retrieved chunks, TMDB results โ€” into a typed SSE stream consumed by the browser.

Why SSE over WebSockets? SSE is unidirectional (server โ†’ client), matching this use case exactly. It works through the CDN without configuration, and EventSource in the browser auto-reconnects on drop. WebSockets add bidirectional protocol overhead that is unnecessary here.

React + TypeScript Frontend

The frontend is a Vite SPA that maintains a live EventSource connection per query. It is laid out as a chat, and every answer carries a step trace: the follow-up rewrite, the knowledge-base verdict and how it was decided, the routing, each source's result, the free lookups vs. Claude calls (purpose, tokens in/out), what the combiner received, any links the guardrail removed, and the model. Older turns fold to a one-line summary. An optional panel (โšก) adds an animated pipeline graph, a Gantt timeline, a typed event log and a context panel; a ๐Ÿงช Evals & ops panel shows the eval tiers, scheduled jobs and ingest history. The AI process is visible, not a black box.

04 A Query, Step by Step

Tracing "Show me good bank heist movies" through the full stack:

1

Understand + knowledge-base lookup: a first question needs no rewrite (no LLM call); the question is embedded and searched in Milvus (hybrid BM25+dense), and the relevance gate decides whether the passages are useful. Then the supervisor calls Claude to classify intent โ†’ routes to all three agents in parallel: tmdb + rag + search

2

TMDB agent calls Claude to extract intent (discover, genre: Crime/Thriller) โ†’ queries TMDB API โ†’ calls Claude to write a grounded answer citing specific films with ratings

3

RAG agent reuses the knowledge-base passages the gate kept (no second search) โ†’ calls Claude to write a knowledge-based answer

4

Search agent sends the query to Tavily โ†’ retrieves current web results โ†’ calls Claude to ground the answer in recent criticism and best-of lists

5

Synthesiser receives all three outputs, calls Claude to merge them by question, not by source โ€” one list, overlapping films deduplicated, sources credited inline, disagreements noted where they occur

6

SSE stream delivers typed events to the browser as they occur: pipeline_start โ†’ kb_lookup โ†’ routing_decision โ†’ agent_start โ†’ token (ร—N) โ†’ tmdb_results โ†’ chunks_retrieved โ†’ agent_end โ†’ done

Total latency: typically 3โ€“6 seconds. First tokens appear within ~1 second of submitting. The parallel agent fan-out means all three agents run concurrently โ€” if they ran sequentially it would take 3ร— as long.

05 Technical Highlights

๐Ÿ”€
Hybrid retrieval (BM25 + dense, weighted fusion) Outperforms either method alone. BM25 catches exact name matches; embeddings catch semantic similarity. A weighted score merge (dense 0.7, BM25 0.3) combines them; it beat rank-only RRF on the retrieval evals.
โšก
Parallel agent execution TMDB, RAG, music and web search run concurrently in one LangGraph superstep. Each agent also parallelises its own internal fetches โ€” movie details and actor filmography are fetched simultaneously.
๐Ÿง 
Multi-turn conversation memory LangGraph's MemorySaver + thread_id keeps the conversation, and each follow-up is rewritten into a standalone question for the agents. "What about his other films?" works correctly without re-stating context.
๐Ÿ“š
Knowledge base first, with a calibrated gate Every question checks the curated corpus before routing. Thresholds on dense cosine similarity, calibrated on 68 labelled questions, decide relevance without an LLM call for most questions; a small grader handles the unsure band.
๐Ÿ”ญ
Observable pipeline Every internal event โ€” rewrite, knowledge-base verdict, routing decision, agent start/end, LLM call, retrieved chunks โ€” streams to the UI, and each answer keeps its own step trace with Claude calls and tokens. The AI reasoning process is transparent, not a black box with a spinner.
๐ŸŽฌ
Filmography comparison intent A movie_and_person intent type fetches movie detail and actor filmography in parallel, sorts by rating, and hands the ranked list to the synthesis LLM โ€” turning "is this their best film?" from a non-answer into a precise ranked response.
๐Ÿš€
Production deployment Full Docker Compose stack on a cloud VPS: Milvus + etcd + MinIO + FastAPI + React. Nginx reverse proxy. A CDN/WAF proxy for TLS, caching and DDoS protection. Live at smartmoviesearch.com.

06 Full Stack Summary

Layer Technology Role
OrchestrationLangGraph 1.1Multi-agent state machine with conditional routing and conversation memory
LLM inferenceAnthropic Claude (haiku / sonnet / opus tier)All reasoning: follow-up rewriting, relevance grading, routing, intent extraction, answer generation
Vector DBMilvus 2.5Hybrid BM25 + dense search over the movie knowledge corpus
EmbeddingsOpenAI text-embedding-3-small1536-dim dense vectors for semantic retrieval
Movie dataTMDB APIReal-time film/TV metadata, cast, ratings, trending, person filmography
Web searchTavily APICurrent web results as a third retrieval source
BackendFastAPI + uvicornAsync SSE streaming, typed event protocol
FrontendReact + TypeScript + ViteChat UI with per-answer step trace, optional pipeline visualisation, dark/light theme
InfrastructureDocker Compose + Nginx + CDNContainerised deployment, reverse proxy, SSL termination, CDN