Skip to content

An AI book recommendation system built with Streamlit and Ollama. It uses 'nomic-embed-text' for semantic search and 'llama3.2:1b' for generating in-depth analyses of books and user queries.

License

Notifications You must be signed in to change notification settings

Arfazrll/OllamaLLM-RecomendationSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š AI Book Discovery Platform

Streamlit Ollama Python License

Discover your next favorite book with AI-powered semantic search and intelligent analysis

✨ Features β€’ πŸš€ Quick Start β€’ πŸ’‘ How It Works β€’ πŸ“– Usage β€’ πŸ› οΈ Tech Stack

Demo

🌟 Overview

AI Book Discovery Platform is an intelligent book recommendation system that understands natural language queries and provides deep, contextual book recommendations. Unlike traditional search systems that rely on keyword matching, this platform uses cutting-edge AI to understand the semantic meaning of your search and provides expert-level analysis for each recommendation.

🎯 What Makes It Special?

Traditional Search: "science fiction AI"
   β†’ Returns books with those exact keywords

AI Search: "I'm looking for a sci-fi novel that explores AI consciousness"
   β†’ Understands themes, context, and intent
   β†’ Finds books about AI ethics, sentience, and philosophical questions
   β†’ Provides expert analysis of why each book matches your needs

✨ Features

πŸ” Semantic Search Engine

  • Natural language understanding powered by nomic-embed-text
  • No need for exact keyword matching
  • Searches by meaning, theme, and context

🧠 AI-Powered Analysis

  • Query Analysis: Understand your reading preferences and search intent
  • Expert Book Reviews: Get AI-generated summaries, themes, and audience insights
  • Reader Profiling: Discover what type of reader you are based on your searches

πŸ“Š Flexible Data Management

  • Default curated book dataset included
  • Upload your own custom CSV datasets
  • Support for any book collection with titles and descriptions

🏠 100% Local & Private

  • Runs entirely on your machine using Ollama
  • No data sent to external APIs
  • Complete privacy and control

⚑ Real-time Processing

  • Instant semantic search results
  • Dynamic AI analysis generation
  • Responsive Streamlit interface

πŸš€ Quick Start

Prerequisites

Before you begin, ensure you have:

  • Python 3.8+ installed
  • Ollama running locally (Install Ollama)
  • Required AI models pulled

Step 1: Install Ollama & Pull Models

# Install Ollama (if not already installed)
# Visit https://ollama.ai for installation instructions

# Pull required models
ollama pull nomic-embed-text
ollama pull llama3.2:1b

Step 2: Clone & Install

# Clone the repository
git clone https://github.com/yourusername/ai-book-discovery.git
cd ai-book-discovery

# Install dependencies
pip install -r requirements.txt

Step 3: Launch the App

streamlit run OllamaLLM.py

The app will open in your browser at http://localhost:8501 πŸŽ‰


πŸ’‘ How It Works

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   User Query Input                      β”‚
β”‚         "I want a fantasy book about dragons"           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Embedding Generation                       β”‚
β”‚           (nomic-embed-text via Ollama)                 β”‚
β”‚  Query β†’ [0.234, -0.891, 0.456, ...] (vector)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚            Semantic Similarity Search                   β”‚
β”‚         Compare query vector with all books             β”‚
β”‚         Using Cosine Similarity Algorithm               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Top Matches Retrieved                      β”‚
β”‚    Books ranked by semantic relevance score             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           AI Analysis Generation                        β”‚
β”‚          (llama3.2:1b via Ollama)                       β”‚
β”‚  β€’ Reader Profile    β€’ Search Intent                    β”‚
β”‚  β€’ Collection Themes β€’ Individual Book Analysis         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

The Magic Behind Semantic Search

Traditional Keyword Search:

if "dragon" in book_description:
    return book  # Simple string matching

AI Semantic Search:

# Understands meaning and context
query_embedding = embed("I want a fantasy book about dragons")
book_embedding = embed("Epic tale featuring mythical creatures and fire-breathing beasts")

similarity = cosine_similarity(query_embedding, book_embedding)
# High similarity even without exact word "dragon"!

πŸ“– Usage

Basic Search

  1. Enter Your Query: Type a natural language description of what you're looking for
Examples:
- "A thriller that keeps me on the edge of my seat"
- "Books about personal growth and mindfulness"
- "Historical fiction set during World War II"
- "Funny books that will make me laugh out loud"
  1. Get Recommendations: View semantically matched books with relevance scores

  2. Explore AI Analysis:

    • Read the comprehensive query analysis
    • Expand individual books for expert insights

Using Custom Datasets

  1. Prepare Your CSV: Ensure it has at least these columns:

    • Title (required)
    • Description (required)
    • Optional: Authors, Category, Price, etc.
  2. Upload: Use the sidebar file uploader

  3. Search: Your custom books are now searchable!

Example Workflow

πŸ” User Query:
"I need a book that helps me understand human psychology"

πŸ€– AI Understanding:
- Intent: Educational self-improvement
- Themes: Psychology, human behavior, mental processes
- Reader Profile: Curious learner seeking knowledge

πŸ“š Top Recommendations:
1. "Thinking, Fast and Slow" (95% match)
   Expert Analysis:
   β€’ Summary: Explores dual-process theory of mind
   β€’ Themes: Cognitive biases, decision-making, rationality
   β€’ Audience: Psychology enthusiasts, professionals

2. "The Power of Habit" (92% match)
   Expert Analysis:
   β€’ Summary: Examines habit formation and behavioral change
   β€’ Themes: Neuroscience, productivity, self-improvement
   β€’ Audience: Self-help readers, behavioral scientists

πŸ› οΈ Tech Stack

Core Technologies

Component Technology Purpose
Frontend Streamlit Interactive web interface
LLM Runtime Ollama Local AI model execution
Embedding Model nomic-embed-text Semantic understanding
Generative Model llama3.2:1b Text analysis & insights
Data Processing Pandas Dataset manipulation
ML Algorithms Scikit-learn Similarity calculations

AI Models Explained

πŸ”· nomic-embed-text

  • Purpose: Convert text into numerical vectors (embeddings)
  • Size: ~274MB
  • Use Case: Semantic search and similarity matching
  • Speed: Fast inference (~50ms per query)

πŸ”Ά llama3.2:1b

  • Purpose: Generate human-like analytical text
  • Size: ~1.3GB
  • Use Case: Query analysis and book insights
  • Speed: Moderate (~2-3s per analysis)

πŸ“‚ Project Structure

ai-book-discovery/
β”œβ”€β”€ OllamaLLM.py              # Main application file
β”œβ”€β”€ BooksDataset.csv          # Default book dataset
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ README.md                 # This file
β”œβ”€β”€ assets/                   # Images and demos
β”‚   └── demo.gif
└── .gitignore

🎨 Features in Detail

1. Semantic Search Engine

How traditional search fails:

Query: "Books about overcoming adversity"
Traditional: Searches for exact words "overcoming" AND "adversity"
Result: Misses books about "triumph", "resilience", "perseverance"

How AI search succeeds:

Query: "Books about overcoming adversity"
AI Understanding: Concepts of struggle, growth, resilience, triumph
Result: Finds all thematically related books, regardless of exact wording

2. Comprehensive Query Analysis

After each search, get insights into:

  • πŸ“Š Reader Profile: What your search says about you

    "You appear to be seeking intellectually stimulating content 
     with practical applications in daily life."
    
  • 🎯 Search Intent: What you're really looking for

    "Intent: Self-improvement through understanding psychological 
     principles and human behavior patterns."
    
  • πŸ“š Collection Themes: Common threads in recommendations

    "This collection emphasizes cognitive science, behavioral 
     psychology, and evidence-based self-development."
    

3. Expert Book Analysis

Click on any recommended book to reveal:

  • ✍️ Executive Summary: Concise overview of the book's content
  • 🎭 Key Themes: Main topics and concepts explored
  • πŸ‘₯ Target Audience: Who will benefit most from this book

πŸ”§ Configuration

Customizing AI Models

Edit the model names in OllamaLLM.py:

# For embedding (search)
EMBEDDING_MODEL = "nomic-embed-text"  # Change to your preferred embedding model

# For text generation (analysis)
LLM_MODEL = "llama3.2:1b"  # Options: llama3.2:3b, mistral, etc.

Adjusting Search Results

# Number of recommendations to show
TOP_K = 5  # Change to show more or fewer results

# Minimum similarity threshold
MIN_SIMILARITY = 0.3  # Range: 0.0 to 1.0

πŸ› Troubleshooting

Common Issues

Problem: Connection refused error

# Solution: Ensure Ollama is running
ollama serve

Problem: Models not found

# Solution: Pull the required models
ollama pull nomic-embed-text
ollama pull llama3.2:1b

Problem: Slow performance

# Solution: Use a smaller LLM model
# In OllamaLLM.py, change to:
LLM_MODEL = "llama3.2:1b"  # Instead of larger models

Problem: Out of memory

# Solution: Close other applications or use quantized models
ollama pull llama3.2:1b-q4_0  # Quantized version uses less RAM

πŸ“Š Performance Metrics

Operation Time (avg) Notes
Initial embedding generation 2-5 min One-time per dataset
Query embedding ~50ms Per search
Similarity search ~100ms For 10K books
AI analysis generation 2-3s Per query
Individual book analysis 1-2s On-demand

System Requirements:

  • RAM: 8GB minimum (16GB recommended)
  • CPU: Modern multi-core processor
  • Storage: ~2GB for models

πŸ’‘ Use Cases

For Readers

  • Discover books based on mood or current interests
  • Find books similar to ones you've enjoyed
  • Explore new genres with AI guidance

For Librarians

  • Help patrons find books more effectively
  • Manage and search large catalogs
  • Provide personalized recommendations

For Book Clubs

  • Find books matching group preferences
  • Generate discussion themes automatically
  • Analyze book connections and themes

For Researchers

  • Search academic books by concept
  • Find related literature quickly
  • Analyze book themes and trends

πŸ™ Acknowledgments

  • Ollama Team for making local LLMs accessible
  • Streamlit for the amazing web framework
  • Nomic AI for the excellent embedding model
  • Meta AI for the Llama 3.2 model
  • The open-source community for inspiration and support

πŸŽ“ Learn More

Related Resources


About

An AI book recommendation system built with Streamlit and Ollama. It uses 'nomic-embed-text' for semantic search and 'llama3.2:1b' for generating in-depth analyses of books and user queries.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages