Machine LearningAI

Semantic LLM Book Recommender

3 min read
Semantic LLM Book Recomender

Traditional book recommendation systems rely on keyword matching or collaborative filtering - they find books with similar words, or books liked by similar users. This project takes a fundamentally different approach: it uses OpenAI text embeddings to convert book descriptions into semantic vectors, stores them in a ChromaDB vector database, and retrieves the most contextually relevant books based on the meaning of a user's natural language query - not just the words used. Results are then re-ranked by emotional tone (Happy, Sad, Suspenseful, Angry, Surprising, Neutral) using pre-computed emotion scores derived from each book's description. The result is a recommendation system that genuinely understands what kind of reading experience a user is looking for.

🎯 The Challenge

Existing book discovery tools (Goodreads, Amazon) are either popularity-based or require users to know specific titles and authors - they fail when a user wants something like "a slow-burn psychological thriller set in a remote location with an unreliable narrator." No open-source tool existed that combined semantic understanding of reading intent with emotional tone filtering in a single, interactive interface. The challenge was to build a RAG-style retrieval pipeline from scratch using modern LLM tooling and make it accessible to any user.

⚙️ The Action

  • Curated and preprocessed a book dataset with descriptions, categories, cover images, and ISBNs
  • Generated emotion scores (joy, sadness, anger, fear, surprise, neutral) for each book description using NLP emotion classification, stored as columns in the dataset
  • Used LangChain's TextLoader and CharacterTextSplitter to load and chunk book descriptions for indexing
  • Generated dense vector embeddings for all book descriptions using OpenAI's text embedding model via LangChain OpenAI integration
  • Stored all embeddings in a ChromaDB vector database for fast cosine similarity retrieval
  • Built a two-stage retrieval function: (1) fetch top-50 semantic matches from ChromaDB, (2) apply category filter, then re-rank by emotional tone score
  • Designed a Gradio Blocks interface with a text query input, category dropdown, tone dropdown, and a visual gallery output showing book covers and truncated descriptions
  • Configured the app for deployment on Hugging Face Spaces with a GitHub Actions CI/CD workflow

📊 The Impact

  • Semantic search returns contextually relevant books even when zero query words appear in a book's description - a fundamental improvement over keyword search
  • Dual filtering (category + emotional tone) enables personalisation that matches not just topic but reading mood - a unique capability not found in mainstream tools
  • The two-stage retrieval (top-50 → filter → top-16) balances recall (broad semantic search) with precision (focused, relevant final results)
  • GitHub Actions CI/CD workflow configured for automated deployment - shows understanding of production engineering beyond just model building
  • Demonstrates LangChain + OpenAI + ChromaDB - the core modern LLM application stack used in production RAG systems across the industry

Technologies Used

PythonHugging Face TransformersOpenAI APIGradioPandasNumpy