Instructions to use Anirudh1950/Hybrid-Search-Agent with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Anirudh1950/Hybrid-Search-Agent with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Anirudh1950/Hybrid-Search-Agent") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Project page: https://huggingface.co/spaces/Anirudh1950/Hybrid-Search-Agent
Contextual Personal Assistant with Hybrid Search
This project implements a lightweight conversational agent that answers user queries using:
- Static knowledge from a PDF or text document
- Simulated memory from previous user interactions
- Cosine similarity-based retrieval over embedded document chunks
- Natural language generation using OpenAI's GPT-3.5-turbo
💡 Features
- Embeds PDF content using Sentence Transformers (
all-MiniLM-L6-v2) - Retrieves top-k relevant chunks using cosine similarity
- Merges current query with chat history and document context
- Generates helpful, context-aware answers
- Includes fallback rule-based response if OpenAI API fails
🛠 How to Run
- Place a PDF file named
movie_script.pdfin the same directory. - (Optional) Create
memory.jsonto simulate past interactions. - Install dependencies:
pip install -r requirements.txt
- (Optional) Set your OpenAI API key to enable LLM answers. Without a key, the app falls back to heuristic responses.
# PowerShell (Windows)
$env:OPENAI_API_KEY="sk-..."
# bash
export OPENAI_API_KEY="sk-..."
- Run the assistant:
python app.py
🔧 CLI Options
python app.py --help
--pdf PATH: Path to the source PDF (default:movie_script.pdf)--memory PATH: Path tomemory.json(default:memory.json)--top-k N: Number of chunks/memories to retrieve (default: 5)--model NAME: SentenceTransformer model (default:all-MiniLM-L6-v2)--no-openai: Disable OpenAI and force fallback answers--once: Ask a single question and exit
Examples:
# One-shot question (prompts once and exits)
python app.py --once
# Use a different PDF
python app.py --pdf my_notes.pdf
# Disable OpenAI and rely on document+memory only
python app.py --no-openai
📁 Memory Format (memory.json)
[
{ "question": "What is the movie about?", "answer": "It's a sci-fi film set in the future." },
{ "question": "Who is the main character?", "answer": "The main character is Neo." },
{ "question": "What is the Matrix?", "answer": "A simulated reality controlled by machines." }
]
🗂️ Caching
- Embeddings are cached under
.cache/tied to the PDF path and modified time. - If you replace the PDF, the cache automatically refreshes.
❓Troubleshooting
- If you see "Missing PDF", ensure
movie_script.pdfexists or pass--pdf. - If answers seem generic, set
OPENAI_API_KEYor ensure the PDF has extractable text. - If using a GPU PyTorch build is desired, install a CUDA-enabled
torchdistribution accordingly.
Source code: https://github.com/rudzz1950/Hybrid-Search-Agent
Run locally
pip install -r requirements.txt
python app.py
app.py is a Gradio app; the original project scripts are unchanged alongside it.