How yash2010/recommendation_system works
Purpose and Entry Points
This is a semantic movie recommendation service: it ingests TMDB metadata, stores movies and user interactions in SQLite, builds a sentence-embedding index, and serves search/recommendation APIs plus a static UI. Runtime entry point is api.py; offline operational entry points are scripts/fetch_tmdb.py, scripts/csv2db.py, scripts/build_index.py, and expander_train.py.
Data Acquisition and Preparation
The TMDB pipeline fetches multilingual movie records, applies filtering/normalization, and exports checkpointed datasets for database import. TMDB is an external dependency authenticated by TMDB_TOKEN.
• data_pipeline/pipeline.py
• data_pipeline/fetcher.py
• data_pipeline/processor.py
• data_pipeline/exporter.py
• data_pipeline/config.yaml
The intended boundary is file-based: pipeline output (CSV or Parquet) is imported into SQLite separately rather than queried directly by the serving layer.
Persistent Catalog and Feedback Store
SQLite is the system of record for movie metadata, users, and interactions. The database layer supports feedback/history needed for eventual personalization, while the current retrieval path remains content-based.
• database.py
• scripts/csv2db.py
User interaction writes (click, rate, watch) enter through the API and are persisted independently of embedding-index generation.
Embedding Index and Retrieval
Index construction embeds each movie using the external Sentence Transformers model all-MiniLM-L6-v2, producing artifact files aligned with movie metadata. At serving time, the recommender embeds the query and performs cosine-similarity ranking over the loaded NumPy embedding matrix; it also supports title lookup, genre filtering, and item-to-item similarity.
• scripts/build_index.py
• recommender.py
• api.py
This creates a deployment consistency boundary: SQLite catalog contents and artifacts/embeddings.npy must be rebuilt/kept aligned after catalog changes.
Query Expansion Subsystem
Before semantic retrieval, requests may be enriched through a pluggable expander abstraction. Ollama is an external local LLM runtime; the local option runs a repository-trained PyTorch seq2seq model and falls back to Ollama when no usable checkpoint exists.
• expanders/base.py
• expanders/ollama_expander.py
• expanders/local_expander.py
• config/api.yaml
Expansion is optional per request and is selected globally by API configuration, making it a pre-retrieval transformation rather than a retrieval-model concern.
Custom Expander Training and Model
The repository includes a from-scratch transformer encoder-decoder with attention and interchangeable tokenizers. Training data generation can use Ollama; training emits versioned checkpoints, from which the local expander selects the best validation-loss run.
• expander_train.py
• expander_model/expander_model.py
• expander_model/encoder.py
• expander_model/decoder.py
• config/expander_train.yaml
API and Client Boundary
FastAPI owns startup/lifespan initialization, access-code enforcement, REST endpoints, and static-file delivery. It coordinates recommender, expander, and database dependencies; browser UI logic is deliberately separate and served as static content.
• api.py
• static/index.html
• static/Privacy.html
• static/Terms.html
Material runtimes are Python/FastAPI, SQLite, PyTorch, Sentence Transformers, NumPy artifacts, and optionally Ollama. Configuration is YAML-based, with secrets supplied through environment variables.
Main entry points: recommender.py Semantic recommender · api.py FastAPI service · database.py Movie and feedback store · local_expander.py Pluggable query expander
Components 19
Catalog ingestion
- TMDB API · Authenticated with TMDB_TOKEN.
- TMDB pipeline
data_pipeline/pipeline.py - Multilingual fetcher
data_pipeline/fetcher.py - Filter and normalize
data_pipeline/processor.py - Dataset exporter · Writes checkpointed CSV or Parquet for separate import.
data_pipeline/exporter.py - Catalog datasets
- CSV-to-SQLite import
scripts/csv2db.py
Embedding index
- Index builder · Must be rerun when catalog contents change.
scripts/build_index.py - all-MiniLM-L6-v2
- Embedding matrix · Aligned with the SQLite movie catalog.
Query expansion
- Ollama · Used for expansion and optional training-data generation.
- Expander training · Emits versioned checkpoints selected by validation loss.
expander_train.py - Custom seq2seq transformer
expander_model/expander_model.py - Expander checkpoints
- Pluggable query expander · Uses local checkpoints or falls back to Ollama.
expanders/local_expander.py
API and client
- Semantic recommender · Ranks query embeddings and supports title, genre, and similar-item lookup.
recommender.py - FastAPI service · Owns startup, access-code enforcement, REST, and static delivery.
api.py - Static browser UI
static/index.html
Other components
- Movie and feedback store · System of record for catalog, users, and interactions.
database.py
Connections 23
- TMDB API → Multilingual fetcher: movie records
- Multilingual fetcher → Filter and normalize: raw metadata
- Filter and normalize → Dataset exporter: normalized movies
- TMDB pipeline → Multilingual fetcher: orchestrates
- Dataset exporter → Catalog datasets: exports
- Catalog datasets → CSV-to-SQLite import: imports
- CSV-to-SQLite import → Movie and feedback store: catalog rows
- Movie and feedback store → Index builder: movie metadata
- all-MiniLM-L6-v2 → Index builder: embeds movies
- Index builder → Embedding matrix: builds
- Ollama → Expander training: optional training data
- Custom seq2seq transformer → Expander training: trains
- Expander training → Expander checkpoints: writes
- Expander checkpoints → Pluggable query expander: best checkpoint
- Ollama → Pluggable query expander: fallback expansion
- Pluggable query expander → Semantic recommender: expanded query
- all-MiniLM-L6-v2 → Semantic recommender: embeds query
- Embedding matrix → Semantic recommender: similarity matrix
- Movie and feedback store → Semantic recommender: catalog metadata
- FastAPI service → Pluggable query expander: optional request expansion
- FastAPI service → Semantic recommender: search and recommendations
- FastAPI service → Movie and feedback store: click, rate, watch writes
- FastAPI service → Static browser UI: serves