How stephensook/trace-forensic-search works
1. What this repo is
Trace is a local-first semantic search system for matching missing-person and unidentified-remains records. Architecturally it is a three-tier app: a React frontend, a FastAPI backend, and a local Actian VectorAI DB instance used as the retrieval engine.
2. Core runtime boundary
The backend does not own the search index; it orchestrates ingestion, embedding, filtering, and ranking, then delegates vector lookup to Actian VectorAI DB over local gRPC on port 50051. That makes the database the central persistence and retrieval boundary.
3. Data source and demo corpus
The data/synthetic area contains generated case data (cases.json) and the generator used to build it. This synthetic corpus is the main ingest target for the demo and test suite, so the system is designed around offline, reproducible records rather than live external feeds.
4. Ingestion pipeline
backend/ingest.py is the load path from JSON cases into the vector database. It uses deterministic point IDs, prepares metadata, computes embeddings, and writes each case as an idempotent record so re-ingesting the same case does not duplicate it.
5. Embedding subsystem
backend/embeddings.py encapsulates the local model stack described in the README: SapBERT, BGE-M3, and CLIP. The important architectural point is that the system is multi-vector, not single-vector: different case attributes are embedded into separate named spaces for better recall and cleaner ranking.
6. Vector schema and search model
Search is organized around four semantic channels: physical description, circumstances, clothing, and image-based evidence. Each channel is searched independently in the vector DB, then the backend fuses results with Reciprocal Rank Fusion before presenting ranked matches.
7. Metadata filtering boundary
backend/filters.py applies non-semantic constraints such as sex, age range, state, case type, and date window before vector search runs. This is a major architectural boundary because it narrows the candidate set early and avoids spending vector retrieval budget on impossible matches.
8. API layer
backend/main.py exposes the FastAPI service, while backend/schemas.py defines the request/response contracts used by the UI and tests. backend/search.py likely contains the orchestration logic for query embedding, filtered retrieval, fusion, and confidence scoring.
9. Frontend structure
The frontend is a single-page React app built with Vite, TanStack Query, and Tailwind. The main feature areas are search input and filters, result cards, case detail pages, and a sidebar/header layout that supports browsing and explanation of matches.
10. Client-server flow
The browser sends search and case-detail requests through frontend/src/lib/api.ts to the backend API. The backend returns both ranked candidates and explanatory fields such as “Why This Matched,” which the frontend renders in dedicated result and detail components.
11. Operational environment
docker-compose.yml brings up the local VectorAI DB service, while the backend runs in a Python 3.12 environment with local model inference. The repo is intentionally offline after setup, which is important because the data includes sensitive forensic-style records.
12. Testing and confidence
The repository has substantial backend coverage in backend/tests for config, filters, ingestion, schemas, search, synthetic data, and the API surface, plus frontend Vitest checks. This suggests the key correctness risks are in query construction, data normalization, and ranking behavior rather than UI rendering alone.
13. What to draw in an architecture diagram
Show the browser UI on one side, FastAPI in the middle, local embedding models as a separate service/process boundary inside the backend runtime, and Actian VectorAI DB as the persistence/search engine on the other side. Add the synthetic data generator and ingest path as a separate offline pipeline feeding the database, with hard filters happening before multi-vector retrieval and rank fusion happening inside the backend.
Main entry points: search.py Search Orchestrator · main.py FastAPI API · api.ts API Client · docker-compose.yml VectorAI DB
Components 15
Frontend
React SPA for searching, browsing, and explaining matches
- App Shell · Top-level client application and route composition
frontend/src/App.tsx - Search Panel · Query entry and filter controls for case search
frontend/src/components/TraceSearchPanel.tsx - Results Panel · Renders ranked matches and match explanations
frontend/src/components/TraceResultsPanel.tsx - Case Detail · Detailed case view for a selected record
frontend/src/pages/CaseDetail.tsx - API Client · Browser-side request layer for backend calls
frontend/src/lib/api.ts
Backend
FastAPI orchestration layer for filtering, embedding, retrieval, and ranking
- FastAPI API · HTTP surface for search and case detail requests
backend/main.py - Contracts · Request and response models shared by UI and tests
backend/schemas.py - Search Orchestrator · Coordinates query processing, retrieval, fusion, and scoring
backend/search.py - Filters · Applies sex, age, state, case type, and date constraints before retrieval
backend/filters.py - Embeddings · Multi-vector local embedding stack for different semantic channels
backend/embeddings.py - Ingest · Idempotent load path from synthetic cases into vector storage
backend/ingest.py
Data
Synthetic forensic corpus and offline generation pipeline
- Case Generator · Builds reproducible synthetic case corpus for demo and tests
data/synthetic/generate_cases.py - Case Corpus · Synthetic missing-person and unidentified-remains records
data/synthetic/cases.json
Infra
Local runtime and container orchestration
- VectorAI DB · Local Actian VectorAI retrieval and persistence boundary
docker-compose.yml - Compose Stack · Brings up local database and supporting services
docker-compose.yml
Connections 20
- App Shell → Search Panel: renders · The app shell composes search controls
- App Shell → Results Panel: renders · The app shell composes result views
- App Shell → Case Detail: routes to · The app shell supports case detail navigation
- Search Panel → API Client: queries · Search UI submits requests through the API client
- Case Detail → API Client: loads · Detail page fetches case data through the API client
- Results Panel → API Client: refreshes · Results view may refetch or update displayed matches
- API Client → FastAPI API: calls · Browser requests go to the FastAPI service
- FastAPI API → Contracts: uses · API endpoints validate payloads with shared contracts
- FastAPI API → Search Orchestrator: delegates · HTTP handlers forward search work to orchestration logic
- Search Orchestrator → Filters: applies · Candidate narrowing happens before semantic retrieval
- Search Orchestrator → Embeddings: embeds · Queries are expanded into multiple semantic channels
- Search Orchestrator → VectorAI DB: retrieves from · Search is executed against the local vector database
- Search Orchestrator → Contracts: returns · Search results are shaped into API response models
- Embeddings → VectorAI DB: writes spaces · Vector spaces are stored and queried in the DB
- Ingest → Case Corpus: reads · Loader consumes the synthetic corpus
- Ingest → Embeddings: prepares · Ingest computes embeddings for each record
- Ingest → VectorAI DB: loads · Ingest writes idempotent case records into the DB
- Case Generator → Case Corpus: generates · Offline generator produces the demo dataset
- Compose Stack → VectorAI DB: starts · Compose launches the local retrieval engine
- FastAPI API → Compose Stack: depends on · Backend expects the local stack to be available