Providers
Vector Databases

Vector Databases

R2R provides a flexible and provider-agnostic approach to integrate with various vector databases for storing and retrieving vector embeddings. The framework includes built-in support for the following vector database providers:

  • Local (SQLite)
  • PGVector
  • Qdrant

Toggling Between Vector DB Providers

To toggle between different vector database providers, you need to update the vector_database section of the configuration file (config.json). For example:

"vector_database": {
    "provider": "local",
    "collection_name": "demo_vecs"
}

By changing the provider value to "local", "pgvector", or "qdrant", you can switch between the previously mentioned supported vector database providers.

Local Implementation (SQLite)

The LocalVectorDB class is an implementation of the VectorDBProvider that uses SQLite as the underlying storage. It stores vector entries along with their metadata in a SQLite database.

Key features of the LocalVectorDB implementation:

  • Initializes a SQLite database and creates a table for storing vector entries.
  • Supports upserting vector entries with their associated metadata.
  • Performs similarity search using cosine similarity calculation.
  • Allows filtered deletion of entries based on metadata key-value pairs.
  • Retrieves unique values for a specific metadata field.

PGVector Implementation

The PGVectorDB class is an implementation of the VectorDBProvider that integrates with the PGVector library for storing and retrieving vector embeddings in a PostgreSQL database.

Key features of the PGVectorDB implementation:

  • Connects to a PostgreSQL database using the provided connection details.
  • Initializes a collection with the specified name and dimension.
  • Supports upserting vector entries with their associated metadata.
  • Performs similarity search using the PGVector library's query functionality.
  • Allows filtered deletion of entries based on metadata key-value pairs.
  • Retrieves unique values for a specific metadata field.

Qdrant Implementation

The QdrantDB class is an implementation of the VectorDBProvider that integrates with the Qdrant vector database for storing and retrieving vector embeddings.

Key features of the QdrantDB implementation:

  • Connects to a Qdrant server using the provided host, port, and API key.
  • Initializes a collection with the specified name and dimension.
  • Supports upserting vector entries with their associated metadata.
  • Performs similarity search using Qdrant's search functionality.
  • Allows filtered deletion of entries based on metadata key-value pairs.
  • Retrieves unique values for a specific metadata field.

Configuring Vector DB Providers

To configure a specific vector database provider, you need to set the appropriate environment variables and update the vector_database section of the configuration file (config.json).

Local (SQLite)

  • Set the LOCAL_DB_PATH environment variable to the desired path for the SQLite database file.

PGVector

  • Set the following environment variables with the appropriate values:
    • POSTGRES_USER: PostgreSQL database username
    • POSTGRES_PASSWORD: PostgreSQL database password
    • POSTGRES_HOST: PostgreSQL database host
    • POSTGRES_PORT: PostgreSQL database port
    • POSTGRES_DBNAME: PostgreSQL database name

Qdrant

  • Set the following environment variables with the appropriate values:
    • QDRANT_HOST: Qdrant server host
    • QDRANT_PORT: Qdrant server port
    • QDRANT_API_KEY: Qdrant API key

Make sure to update the vector_database section of the configuration file (config.json) with the desired provider and any additional provider-specific settings.