About: 👋 Hi! I'm Anurag, an Android app developer and open source lover. Let's code and collaborate! ✨
Location:
Delhi, India
Joined:
Jul 22, 2024
🎬 Semantic Search for Movies & Series with MindsDB and FastAPI
Publish Date: Jun 29
24 4
In this post, I’ll walk you through the FastAPI-based backend of BingeMate and how it integrates with MindsDB to enable semantic search, metadata filtering, and even conversational agent responses using a SQL-powered interface.
🧠 What Is BingeMate?
BingeMate is a semantic search and recommendation engine that helps users find the perfect movie or series using natural language queries like:
“Top-rated Netflix thrillers after 2020”
“Feel-good anime with high IMDb ratings”
“Is ‘Dark’ similar to ‘Stranger Things’?”
The backend is powered by FastAPI and connects to a MindsDB knowledge base, which stores semantically indexed chunks of content using LLMs and vectors.
🔎 Accepts a natural language query like "popular kdrama in 2023"
📊 Supports dynamic metadata filters like ?type=Series&genre=Drama
🔁 Filters results by minimum relevance score
/agent — Ask a Question via Agent
@app.get("/agent")defcreate_agent(query:str=Query(...,description="Question to ask the agent"),description:Optional[str]=Query(None,description="Description of the agent")):result=query_agent(query=query)return{"result":result}
This endpoint interacts with a MindsDB agent that answers natural language questions based on pre-trained or fine-tuned SQL logic.
@app.post("/api/projects/mindsdb/jobs")defcreate_job(project:str,job_name:str,query:str):return{"message":f"Job '{job_name}' created in project '{project}' with query: {query}"}
✏️ Note : The MindsDB Job endpoint is used to schedule specific timepoints at which an SQL query will be executed.
🔧 mindsdb_client.py — Query Logic
This module handles communication with MindsDB via SQL.
Search the Knowledge Base
defquery_knowledge_base(search_query:str,min_relevance:float=0.25,metadata:dict=None):conditions=[f'content = "{search_query}"',f"relevance >= {min_relevance}"]ifmetadata:forkey,valueinmetadata.items():conditions.append(f"{key} = '{value}'")sql=f"SELECT * FROM my_bingekb WHERE {' AND '.join(conditions)};"query=server.query(sql)df=query.fetch()...
✅ Uses SQL to query my_bingekb table
🧠 Automatically filters results using relevance and metadata (e.g., type, genre)
🔄 Converts results to a JSON-friendly format
Ask a Question to an Agent
defquery_agent(query:str):sql=f"""
SELECT answer FROM my_agent WHERE question = "{query}";
"""df=server.query(sql).fetch()returndf
This enables direct Q&A via a SQL-like agent interface. You can map semantic questions to custom-trained answers.
GET /query?q=best%20series%20on%20netflix&genre=Drama&type=Series
GET /agent?query=Is%20Breaking%20Bad%20better%20than%20Ozark
💡 Final Thoughts
FastAPI + MindsDB gives you a supercharged backend for semantic search and conversational interfaces. Whether you’re building a movie recommender, travel planner, or knowledge assistant—this stack is lightweight, extensible, and LLM-ready.
Now go and check out the implementation of this backend -- BingeMate!
🎬 BingeMate – Your AI-Powered Movie & Series Finder 🎙️📺
BingeMate is a Jetpack Compose Android application that helps users discover movies and series using Voice input and Semantic search powered by MindsDB Knowledge Base and Ollama LLMs.
It combines natural language queries with structured filters like genre, type, year, and IMDb rating to return personalized results from Mindsdb Knowledge base
App's backend link is required to get movie/series data for Semantic/agent search - BingeMate-Backend
🚀 Features
🎤 Voice-Powered Search
Uses Google Speech Services for hands-free querying.
🔍 Semantic Movie/Series Search
Queries are processed through MindsDB's Knowledge Base, which semantically matches user intent to documents (movie/series data) in the database.
📚 Metadata Filters
Users can refine results using:
🎭 genre (e.g., action, comedy)
🎞️ type (movie/series)
📅 year (e.g., 2023)
⭐ IMDb rating (e.g., >8.0)
🤖 Conversational Agent
A built-in agent powered by Ollama (Mistral) responds to natural…
The UI looks so soothing! Great work, mate