QyverLabs Docs
  • 👋Welcome
  • Getting Started
    • 👀Why Qyver?
    • 💻Setup Qyver
    • 🏗️Basic Building Blocks
  • Run In Production
    • 🎯Overview
    • 💻Setup Qyver Server
      • 🧮Configuring your app
      • 📔Interacting with app via API
    • ⚙️Supported Vector Databases
      • Redis
      • Mongo DB
      • Qdrant
  • Concepts
    • 🗓️Combining Multiple Embeddings for Better Retrieval Outcomes
    • 🏹Dynamic Parameters/Query Time weights
  • Reference
    • 🎯Overview
    • ⏰Changelog
  • Help & FAQ
    • 📒Logging
    • ❔Support
Powered by GitBook
On this page
  1. Run In Production
  2. Supported Vector Databases

Mongo DB

PreviousRedisNextQdrant

Last updated 3 months ago

Integrating MongoDB with Qyver

This guide provides step-by-step instructions on configuring and integrating MongoDB with Qyver.

Configuring an Existing Managed MongoDB Instance

To use MongoDB with Qyver, ensure your MongoDB version supports Atlas Vector Search. Refer to the for more details.

Qyver requires access to MongoDB to manage Atlas Search Indexes. MongoDB’s instance size affects how these indexes can be created, listed, and deleted. Specifically:

  • Instances below M10 do not allow these operations via a standard user and require access through the administration API.

  • Larger instances allow direct index management.

To support all instance types, Qyver uses the administration API for index management. This requires an API key with the Project Data Access Admin role. Instructions for creating this key are included below.

Note: The API requires both a project ID and cluster name. Instructions on retrieving this information are also provided.


Configuration Modifications

To integrate MongoDB, add the MongoDBVectorDatabase class and include it in the executor:

from qyver import framework as qv

vector_database = qv.MongoDBVectorDatabase(
    host="<USER>:<PASSWORD>@<HOST_URL>",  # MongoDB connection string, including username and password
    db_name="<DATABASE_NAME>",  # Name of the database (must be created manually)
    cluster_name="<CLUSTER_NAME>",  # Name of the cluster in MongoDB Atlas
    project_id="<PROJECT_ID>",  # Project ID (not the project name)
    admin_api_user="<API_USER>",  # API key user (public key in MongoDB Atlas)
    admin_api_password="<API_PASSWORD>",  # API password (private key in MongoDB Atlas)
    default_query_limit=10,  # (Optional) Maximum number of results per query (defaults to 10)
    # Additional parameters can be passed as kwargs and will be handled by the MongoDB client.
)

Finding Your Project ID

  • In MongoDB Atlas, select your organization from the top left corner.

  • Find your project but do not click on it.

  • Click the Actions (···) menu in the last column and select Copy Project ID.

Alternatively, your Project ID is in the URL when viewing a project: https://cloud.mongodb.com/v2/<PROJECT_ID>#/overview Make sure to copy the correct ID and not the organization ID.

Setting Up the Executor

Once the MongoDBVectorDatabase is configured, assign it to the executor:

...
executor = qv.RestExecutor(
    sources=[source],
    indices=[index],
    queries=[qv.RestQuery(qv.RestDescriptor("query"), query)],
    vector_database=vector_database,  # Use the MongoDBVectorDatabase instance
)
...

Starting a Managed MongoDB Instance

Follow these steps to set up a MongoDB Atlas instance:

  1. Create the Database

    • Sign in to MongoDB Atlas.

    • Create a cluster and note the cluster name.

    • Click Database from the left menu.

    • Once the cluster is created, open it and navigate to the Collections tab.

    • Click Add My Own Data, enter a database name, and create a collection.

  2. Create a Database User and Allow IP Access

    • Click Database from the left menu.

    • Click Connect next to your cluster.

    • In the pop-up, allow access from any IP or specify your machine’s IP.

    • Create a database user with a username and password.

  3. Generate an API Key

    • Go to Access Manager and select your project.

    • Open the API Keys tab.

    • Create an API key with the Project Data Access Admin role.

    • Save the private key (it will not be accessible again).

⚙️
official MongoDB documentation