Project page: https://huggingface.co/spaces/Anirudh1950/Semantic_Search

Semantic Search Project

This project demonstrates semantic search over the Quora Questions dataset using Sentence Transformers. You can run it in two modes:

  • Local in-memory vector search (no external services)
  • Pinecone-managed vector index (optional)

The repository contains:

  • Semantic_Search Project.ipynb β€” original lesson notebook.
  • semantic_search.py β€” runnable CLI script for semantic search.
  • requirements.txt β€” Python dependencies.

Prerequisites

  • Python 3.9+ recommended.
  • Internet access to download models and the dataset the first time you run.

Setup

  1. Create and activate a virtual environment (recommended):
# Create venv (Windows)
py -3 -m venv .venv

# Activate (PowerShell)
. .venv\Scripts\Activate.ps1

# Or activate (cmd.exe)
.venv\Scripts\activate.bat
  1. Install dependencies:
python -m pip install -r requirements.txt

# If "python" is not recognized, use the venv's interpreter directly:
.venv\Scripts\python.exe -m pip install -r requirements.txt

Running Local In-Memory Search

This mode encodes a subset of Quora/QQP questions and performs cosine similarity search locally. No external services are required.

python semantic_search.py --limit 5000 --top-k 10 --batch-size 256 --query "which city has the highest population in the world?"

# If "python" is not recognized, use the venv's interpreter directly:
.venv\Scripts\python.exe semantic_search.py --limit 5000 --top-k 10 --batch-size 256 --query "which city has the highest population in the world?"

Dataset source and fallback

  • The script attempts to use the legacy quora dataset slice.
  • If that is unavailable on your system, it automatically falls back to the supported glue/qqp dataset (Quora Question Pairs) and extracts question1/question2 fields.

Flags:

  • --limit Number of questions to index (default 5000).
  • --top-k Number of results to return (default 10).
  • --batch-size Batch size for encoding (default 256).
  • --query Your search query.

Running With Pinecone (Optional)

  1. Set your Pinecone API key in the environment:
# Windows PowerShell
$env:PINECONE_API_KEY = "YOUR_API_KEY_HERE"

# Windows cmd.exe
set PINECONE_API_KEY=YOUR_API_KEY_HERE
  1. Run the script with --use-pinecone:
python semantic_search.py --use-pinecone --index-name dlai-semantic-search --limit 5000 --top-k 10 --batch-size 200 --query "how do i make chocolate cake?"

Notes:

  • The script automatically creates the Pinecone index if it does not exist.
  • If PINECONE_API_KEY is not set, the script will gracefully fall back to local mode.

Troubleshooting

  • CPU performance: Model encoding can take time without GPU. Reduce --limit to speed up.
  • First-run downloads: Sentence Transformer model and dataset will be downloaded on first run.
  • Dataset fallback: If you encounter "Dataset scripts are no longer supported" for quora, the script already falls back to glue/qqp automatically.
  • Python not recognized: Use py -3 to create the venv and .venv\Scripts\python.exe to run commands if python isn't on PATH.
  • Hugging Face Xet notice: Messages like "Xet Storage is enabled..." are informational and safe to ignore.
  • Pinecone SDK differences: The script includes compatibility handling for common SDK variations.

Using the Notebook

Open Semantic_Search Project.ipynb in Jupyter or VS Code to step through the lesson interactively.


Source code: https://github.com/rudzz1950/Semantic_Search

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/Semantic_Search 1