This project provides a FastAPI-based API to manage vector database operations, including creating indexes, inserting (upserting) data, and performing similarity or ID-based searches. Currently, it supports Pinecone as the vector database provider.
- Create vector indexes in Pinecone.
- Upsert (insert or update) data into the vector database.
- Search for similar vectors or specific IDs with metadata filtering.
- Python 3.12
- FastAPI == 0.109.1
- Pinecone Client == 3.0.0
- Pydantic == 2.5.2
- Uvicorn == 0.24.0
- python-dotenv
- Docker (opcional)
- Construir la imagen:
docker build -t vector-db-api .
- Ejecutar el contenedor:
docker run -d -p 9000:9000 --name vector-db-container vector-db-api
- Verificar que está funcionando:
- La API estará disponible en: http://localhost:9000/docs
- Comandos útiles de Docker:
# Ver logs del contenedor
docker logs vector-db-container
# Detener el contenedor
docker stop vector-db-container
# Eliminar el contenedor
docker rm vector-db-container
Install the dependencies using:
pip install -r requirements.txt
The following environment variables are required:
PINECONE_API_KEY
: Your Pinecone API key.MODEL_NAME
: Name of the embedding model to use.
Run the FastAPI server using Uvicorn:
uvicorn main:app --reload
Para probar los endpoints más fácilmente, puedes usar nuestra colección de Postman: Vector DB API Collection
Creates a vector index in Pinecone.
curl --location 'http://localhost:8000/vector-db/create_index/pinecone' \
--header 'Content-Type: application/json' \
--data '{
"index_name": "startup",
"dimension": 1024,
"metric": "cosine",
"cloud": "aws",
"region": "us-east-1"
}'
Upserts (inserts or updates) data into the specified namespace of a Pinecone index.
curl --location 'http://localhost:8000/vector-db/upsert_data/pinecone/startup' \
--header 'Content-Type: application/json' \
--data '{
"namespace": "products",
"records": [
{
"id": "pc1",
"data": {"name": "computadora mac", "price": 213131.03131},
"metadata": {"tags": ["mac"], "category": "tech", "price": 2000, "id": "pc1"}
},
{
"id": "pc2",
"data": {"name": "computadora linux", "price": 200.03131},
"metadata": {"tags": ["linux"], "category": "tech", "price": 1000, "id": "pc2"}
}
]
}'
Performs a similarity search with optional metadata filters.
curl --location 'http://localhost:8000/vector-db/search/pinecone/startup' \
--header 'Content-Type: application/json' \
--data '{
"query": "quiero comprar un pc",
"top_k": 2,
"ids": ["pc1", "pc2"],
"namespace": "products",
"metadata_filter": {
"category": {
"$eq": "tech"
},
"price": {
"$gt": 200
},
"id": {
"$eq": "pc1"
}
}
}'
This project is licensed under the MIT License.