Skip to content

Pushkarmondal/semantic-search-knowledge-base-using-vector-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vector DB Salon Search API

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

Features

  • 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 (salon vs beautician)
  • Deduplication of results (merges related records like profile/services)

Prerequisites

  • Python 3.9+
  • Pinecone account + API key
  • Google Gemini API key

Setup

1) Install dependencies

Create a virtual environment and install requirements:

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

2) Environment variables

Create a .env file in vector_db/:

PINECONE_API_KEY=your_pinecone_api_key
GOOGLE_API_KEY=your_google_gemini_api_key

Run the API

From the vector_db folder:

fastapi dev main.py

The 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

API

POST /query

Request body

{
  "query": "string"
}

Response

Returns text/plain (not JSON). The response includes the answer plus the retrieved context.

Example queries

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"}'

Dataset format

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"
    }
  }
]

Project structure

  • main.py: FastAPI app, Pinecone index creation, upsert logic, /query endpoint
  • gemini_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)

Notes / common issues

  • If you change embedding model, ensure Pinecone index dimension matches.
  • If you update metadata fields (e.g., city capitalization), re-upsert the dataset.
  • If Gemini key is missing, the server will fail when generating answers.

About

This project is a semantic search API built using FastAPI, Pinecone, and Gemini. It implements a Retrieval-Augmented Generation (RAG) pipeline over a salon dataset, allowing natural language queries to return context-aware answers.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages