Skip to content

About

Scalable Vector Search

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scalable Vector Search

High-performance semantic search microservice built with FastAPI + Pinecone.

Architecture (short)

  • FastAPI async API with lifecycle init for Pinecone + embedding provider.
  • Embeddings: pluggable provider (openai or sentence-transformers).
  • Pinecone holds vectors and metadata; the service auto-creates index if missing.
  • Ingestion is batched and concurrent for throughput; search is optimized for low latency.

Endpoints

  • POST /ingest/bulk - Bulk upsert vectors
    • Body: { "items": [{ "id": "1", "text": "hello", "metadata": {"k":"v"} }, ...] }
    • Response: { "upserted": n, "batch_count": m, "errors": [] }
  • POST /search - Semantic search
    • Body: { "query": "search text", "top_k": 10 }
    • Response: { "results": [{ "id": "...", "score": 0.9, "metadata": {...} }, ...] }
  • GET /health - Liveness
  • GET /ready - Readiness

Quick curl examples

Ingest:

curl -X POST http://localhost:8000/ingest/bulk -H "Content-Type: application/json" \
  -d '{"items":[{"id":"1","text":"Hello world","metadata":{"source":"test"}}]}'

Search:

curl -X POST http://localhost:8000/search -H "Content-Type: application/json" \
  -d '{"query":"hello","top_k":5}'

Pinecone setup

  1. Create an API key at Pinecone.
  2. Set PINECONE_API_KEY, PINECONE_ENV, and PINECONE_INDEX in your environment or .env.
  3. On startup the service will create the index if it does not exist (uses DIMENSION and PINECONE_METRIC).

Environment variables (see env.example)

  • PINECONE_API_KEY, PINECONE_ENV, PINECONE_INDEX
  • EMBEDDING_PROVIDER = openai | sentence-transformers
  • OPENAI_API_KEY (required if EMBEDDING_PROVIDER=openai)
  • TRANSFORMER_MODEL when using sentence-transformers
  • BATCH_SIZE, BATCH_CONCURRENCY, DIMENSION, PINECONE_METRIC

Performance & scaling notes

  • Batching and concurrent upserts reduce overhead for large bulk ingest.
  • Keep the embedding provider choice in mind: local transformer models add startup time and memory; OpenAI delegates compute to the API but adds network latency.
  • Horizontal scaling: run multiple replicas behind a load balancer. Pinecone handles vector storage scaling; keep clients stateless.
  • For <100ms latency target for search, prefer OpenAI embeddings (fast network) or colocate transformer models on the same region. Tweak top_k and use include_values carefully.

Local run (dev)

  1. Copy env.example to .env and fill values.
  2. Create a virtualenv and install:
    pip install -r requirements.txt
  3. Run:
    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Docker

Build:

docker build -t scalable-vector-search:latest .

Run (example):

docker run --rm -p 8000:8000 \
  -e PINECONE_API_KEY=... \
  -e PINECONE_ENV=... \
  -e PINECONE_INDEX=svc-index \
  -e EMBEDDING_PROVIDER=openai \
  -e OPENAI_API_KEY=... \
  scalable-vector-search:latest

Notes and assumptions

  • The service uses threadpool offloading for blocking SDK calls to keep FastAPI event loop responsive.
  • sentence-transformers may load large ML models; on Docker deployments, prefer using EMBEDDING_PROVIDER=openai for smaller images unless you provision GPUs and memory.
  • Ensure your Pinecone index DIMENSION matches the embedding dimension of your chosen model.

About

Scalable Vector Search

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages