Instructions to use Anirudh1950/Semantic_Search with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Anirudh1950/Semantic_Search with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("Anirudh1950/Semantic_Search") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
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
- 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
- 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
quoradataset slice. - If that is unavailable on your system, it automatically falls back to the supported
glue/qqpdataset (Quora Question Pairs) and extractsquestion1/question2fields.
Flags:
--limitNumber of questions to index (default 5000).--top-kNumber of results to return (default 10).--batch-sizeBatch size for encoding (default 256).--queryYour search query.
Running With Pinecone (Optional)
- 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
- 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_KEYis not set, the script will gracefully fall back to local mode.
Troubleshooting
- CPU performance: Model encoding can take time without GPU. Reduce
--limitto 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 toglue/qqpautomatically. - Python not recognized: Use
py -3to create the venv and.venv\Scripts\python.exeto run commands ifpythonisn'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.