Skip to content

Repository files navigation

Vector Conversation Search & Delete API

A FastAPI microservice for vector similarity search, creation/sync of conversation embeddings, and deletion of conversation records. Uses PostgreSQL with pgvector, OpenAI embeddings, and is designed for Docker deployment.


Features

  • Search – Vector similarity search over conversation content (with optional user/session filters)
  • Create / Sync – Sync chats from the database into vector tables (embeddings, chunking, and optional per-message vectors)
  • Delete – Delete conversations by ID or by user (and optional session)
  • Get by ID – Fetch a single conversation by ID
  • Built with FastAPI and async PostgreSQL (asyncpg)
  • API key protection on search, conversations, and insertion routes
  • Swagger UI at /docs, ReDoc at /redoc
  • Docker support for build and run

Project Structure

deletion-api-vectorDB/
├── app/
│   ├── config.py
│   ├── database.py
│   ├── models.py
│   ├── dependencies/
│   │   └── auth.py
│   └── routes/
│       ├── health.py
│       ├── search.py
│       ├── conversations.py
│       └── insertion.py
├── main.py
├── requirements.txt
├── Dockerfile
├── docker-compose.yml
├── .env
└── README.md

API Overview

All endpoints under /search, /conversations, and /api require a valid API key (e.g. in X-API-Key header, depending on your auth setup). The health and root endpoints are unauthenticated.

Search (/search)

Method Path Description
POST /search/ Vector similarity search using a pre-computed embedding. Query params: matching_function. Body: VectorSearchRequest (embedding, match_count, user_id, session_id, additional_filter, similarity_threshold).
POST /search/user Vector similarity search by text query (embeddings generated server-side). Query params: matching_function. Body: VectorSearchRequest with query, user_id, match_count, similarity_threshold, additional_filter.

Responses return a list of ConversationResult (id, content, metadata, similarity) plus total_count and query_info.

Creation / Sync (/api)

Method Path Description
POST /api/vector/sync Sync conversations from the chats table into vector tables. Creates or updates session-level embeddings (and optionally per-message vectors), with chunking and OpenAI embeddings. Returns counts of chats processed, created/updated vectors, and any failures.

No request body. Uses DB config (e.g. USER_VECTOR_TABLE, COMPANY_VECTOR_TABLE, message vector tables) from app.config.

Deletion & Retrieval (/conversations)

Method Path Description
DELETE /conversations/ Delete conversations by a list of IDs. Body: DeleteRequest with ids (list of UUID strings) and table. Returns deleted_count, deleted_ids, success.
DELETE /conversations/user/{user_id} Delete all conversations for a user, optionally scoped to a session. Query params: table, optional session_id. Returns same deletion response shape.
GET /conversations/by_id Get one conversation by ID. Query params: conversation_id (UUID), table. Returns ConversationDetail (id, content, metadata).

Health

Method Path Description
GET /health Health check; returns status and database connectivity.
GET / Root; returns API title and status.

Local Docker Deployment

  1. Build the image

    docker build -t fastapi-conversations .
  2. Run the container

    docker run -d --name delete-api -p 8000:8000 fastapi-conversations
  3. Open http://localhost:8000/docs for Swagger UI.


Configuration

Use a .env file (and/or environment variables) for database URL, OpenAI API key, embedding model, vector dimension, table names, and API key for protected routes. See app/config.py for the full set of options.

About

A FastAPI-based microservice to manage and delete conversation records, designed with modularity and Docker deployment in mind.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages