This project provides a REST API for semantic search over a salon dataset using:
- FastAPI
- Pinecone (vector database)
sentence-transformers/all-MiniLM-L6-v2(embeddings)- Gemini (LLM) to generate a final answer from retrieved context
The API accepts a natural-language query and returns a plain-text response containing:
- the query
- the generated answer
- the retrieved context used
- Creates and manages a Pinecone index (serverless)
- Upserts salon dataset into Pinecone on startup
- Semantic search over salon/beautician records
- Basic intent extraction:
- city extraction from query
- entity type detection (
salonvsbeautician)
- Deduplication of results (merges related records like profile/services)
- Python 3.9+
- Pinecone account + API key
- Google Gemini API key
Create a virtual environment and install requirements:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txtCreate a .env file in vector_db/:
PINECONE_API_KEY=your_pinecone_api_key
GOOGLE_API_KEY=your_google_gemini_api_keyFrom the vector_db folder:
fastapi dev main.pyThe server runs at:
http://127.0.0.1:8000
On startup the app will:
- create the Pinecone index if missing
- load
salons_dataset.json - generate embeddings and upsert vectors
Request body
{
"query": "string"
}Response
Returns text/plain (not JSON). The response includes the answer plus the retrieved context.
curl -X POST "http://127.0.0.1:8000/query" \
-H "Content-Type: application/json" \
-d '{"query":"best salon in Guwahati"}'curl -X POST "http://127.0.0.1:8000/query" \
-H "Content-Type: application/json" \
-d '{"query":"beautician for bridal makeup in New Delhi"}'curl -X POST "http://127.0.0.1:8000/query" \
-H "Content-Type: application/json" \
-d '{"query":"hair spa near Nagaon"}'The project expects a JSON array (default: salons_dataset.json) like:
[
{
"id": "unique_id",
"text": "text that will be embedded and retrieved",
"metadata": {
"city": "Guwahati",
"state": "Assam"
}
}
]main.py: FastAPI app, Pinecone index creation, upsert logic,/queryendpointgemini_client.py: Gemini client +generate_with_model(prompt)salons_dataset.json: salon dataset used for upserting (filename must match your code).env: secrets (not committed)
- If you change embedding model, ensure Pinecone index
dimensionmatches. - If you update metadata fields (e.g.,
citycapitalization), re-upsert the dataset. - If Gemini key is missing, the server will fail when generating answers.