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

  1. Place a PDF file named movie_script.pdf in the same directory.
  2. (Optional) Create memory.json to simulate past interactions.
  3. Install dependencies:
pip install -r requirements.txt
  1. (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-..."
  1. 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 to memory.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.pdf exists or pass --pdf.
  • If answers seem generic, set OPENAI_API_KEY or ensure the PDF has extractable text.
  • If using a GPU PyTorch build is desired, install a CUDA-enabled torch distribution 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.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Space using Anirudh1950/Hybrid-Search-Agent 1