LogoLogo
👋 Get in touch⭐️ GitHub
  • Welcome
  • Getting Started
    • Why Superlinked?
    • Setup Superlinked
    • Basic Building Blocks
  • Run in Production
    • Overview
    • Setup Superlinked Server
      • Configuring your app
      • Interacting with app via API
    • Supported Vector Databases
      • Redis
      • Mongo DB
      • Qdrant
  • Concepts
    • Overview
    • Combining Multiple Embeddings for Better Retrieval Outcomes
    • Dynamic Parameters/Query Time weights
  • Reference
    • Overview
    • Changelog
    • Components
      • Schema
        • Id Schema Object
        • Event Schema
        • Event Schema Object
        • Schema Object
        • Schema
      • Parser
        • Json Parser
        • Dataframe Parser
        • Data Parser
      • Dag
        • Period Time
      • Storage
        • Vector Database
        • Qdrant Vector Database
        • Mongo Db Vector Database
        • Redis Vector Database
        • In Memory Vector Database
      • Space
        • Custom Space
        • Space Field Set
        • Input Aggregation Mode
        • Text Similarity Space
        • Space
        • Categorical Similarity Space
        • Recency Space
        • Number Space
        • Exception
        • Has Space Field Set
        • Image Space Field Set
        • Image Space
      • Query
        • Query Mixin
        • Query Param Value Setter
        • Query Weighting
        • Space Weight Param Info
        • Clause Params
        • Query Descriptor
        • Query
        • Param Evaluator
        • Param
        • Result
        • Query Filter Information
        • Query Filter Validator
        • Natural Language Query Param Handler
        • Query Filters
        • Query Param Information
        • Nlq Param Evaluator
        • Query Vector Factory
        • Nlq Pydantic Model Builder
        • Typed Param
        • Query Clause
        • Nlq
          • Nlq Compatible Clause Handler
          • Nlq Handler
          • Nlq Clause Collector
          • Exception
          • Suggestion
            • Query Suggestions Prompt Builder
            • Query Suggestion Model
          • Param Filler
            • Query Param Model Validator Info
            • Nlq Annotation
            • Query Param Model Builder
            • Query Param Prompt Builder
            • Query Param Model Validator
            • Templates
        • Query Clause
          • Hard Filter Clause
          • Space Weight Map
          • Looks Like Filter Clause
          • Similar Filter Clause
          • Base Looks Like Filter Clause
          • Single Value Param Query Clause
          • Radius Clause
          • Select Clause
          • Overriden Now Clause
          • Nlq System Prompt Clause
          • Looks Like Filter Clause Weights By Space
          • Limit Clause
          • Weight By Space Clause
          • Nlq Clause
          • Query Clause
        • Predicate
          • Binary Op
          • Binary Predicate
          • Query Predicate
        • Query Result Converter
          • Default Query Result Converter
          • Query Result Converter
          • Serializable Query Result Converter
      • Executor
        • Executor
        • Exception
        • Query
          • Query Executor
        • Rest
          • Rest Handler
          • Rest Configuration
          • Rest Descriptor
          • Rest Executor
        • Interactive
          • Interactive Executor
        • In Memory
          • In Memory Executor
      • App
        • App
        • Online
          • Online App
        • Rest
          • Rest App
        • Interactive
          • Interactive App
        • In Memory
          • In Memory App
      • Source
        • Interactive Source
        • Data Loader Source
        • In Memory Source
        • Source
        • Rest Source
        • Types
      • Index
        • Index
        • Effect
        • Util
          • Event Aggregation Effect Group
          • Aggregation Effect Group
          • Aggregation Node Util
          • Effect With Referenced Schema Object
          • Event Aggregation Node Util
      • Registry
        • Superlinked Registry
        • Exception
  • Recipes
    • Overview
    • Multi-Modal Semantic Search
      • Hotel Search
    • Recommendation System
      • E-Commerce RecSys
  • Tutorials
    • Overview
    • Semantic Search - News
    • Semantic Search - Movies
    • Semantic Search - Product Images & Descriptions
    • RecSys - Ecommerce
    • RAG - HR
    • Analytics - User Acquisition
    • Analytics - Keyword Expansion
  • Help & FAQ
    • Logging
    • Support
    • Discussion
  • Policies
    • Terms of Use
    • Privacy Policy
Powered by GitBook
On this page
  • Configuring your existing managed MongoDB
  • Modifications in your configuration
  • Start a managed Mongo DB instance
  • Creating the Database:
  • Creating a Database User and add your IP:
  • Creating the API Key:
  • Example app with Mongo DB

Was this helpful?

Edit on GitHub
  1. Run in Production
  2. Supported Vector Databases

Mongo DB

PreviousRedisNextQdrant

Last updated 4 months ago

Was this helpful?

This document provides clear steps on how to use and integrate MongoDB with Superlinked.

Configuring your existing managed MongoDB

To integrate MongoDB with Superlinked, ensure you are using a version that supports Atlas Vector Search capabilities. Refer to the MongoDB documentation for .

Superlinked requires access to MongoDB to list, create, and delete Atlas Search Indexes. As of writing, MongoDB separates functionality by database instance sizes. If you use anything below M10, the database does not support creating, listing, and deleting the Atlas Search Index via a standard user, only via the administration API. You can read more and also . To support all types, Superlinked uses the aforementioned API to manage the indexes.

Due to the reasons above, an API key with the Project Data Access Admin role is required. More about how to create that can be found .

Note: When using that API, you will need project_id and cluster_name, how to find this information is also described .

Modifications in your configuration

To integrate MongoDB, you need to add the MongoDBVectorDatabase class and include it in the executor. Here’s how you can do it:

from superlinked import framework as sl

vector_database = sl.MongoDBVectorDatabase(
    host="<USER>:<PASSWORD>@<HOST_URL>", # The DB's host URL with the username and password.
    db_name="<DATABASE_NAME>", # Name of your database inside your cluster. You need to create it, the system won't do it automatically.
    cluster_name="<CLUSTER_NAME>", # Name of your cluster inside your project.
    project_id="<PROJECT_ID>", # The ID (not the name) of your project. To see how to find it, read the note below this box.
    admin_api_user="<API_USER>", # The generated API key's user, which called public key on MongoDB Atlas.
    admin_api_password="<API_PASSWORD>", # The API password, generated by MongoDB Atlas, they reference it on Atlas as private key.
    default_query_limit=10, # This optional parameter specifies the maximum number of query results returned. If not set, it defaults to 10.
    # Anything else is handled as kwargs so those will be passed in to the MongoClient. Read more about the possible parameters below.
)

Project ID: to find your Project ID, select you organization in the top left corner of Atlas UI. Afterward, find your project (don't click on it). In the last column ("Actions") expend the menu by clicking on the ellipses (...), then select "Copy Project ID" which will paste it to your clipboard.

Alternatively, click on your project on Atlas and in the URL you will find the id: https://cloud.mongodb.com/v2/12755aca606daa697d3e30b9#/overview where the 12755aca606daa697d3e30b9 before the # and after the https://cloud.mongodb.com/v2/ is your project ID. The organization ID is very similar to this string, but please make sure that you copy the ID after you selected the project!

Once you have configured the MongoDBVectorDatabase, set it as your vector_database in the RestExecutor:

...
executor = sl.RestExecutor(
    sources=[source],
    indices=[index],
    queries=[sl.RestQuery(sl.RestDescriptor("query"), query)],
    vector_database=vector_database, # Or any variable that you assigned your `MongoDBVectorDatabase`.
)
...

Start a managed Mongo DB instance

A step-by-step guide to set up a database, a user, and the required API key.

Creating the Database:

  1. Create your cluster. The cluster name will be needed for the configuration mentioned above. You can choose any other options as they do not impact Superlinked's functionality.

  2. Click on the Database option in the left menu column.

  3. Once the cluster is created, click on its name and then go to the collections tab or click on the Browse Collections button.

  4. Click on Add My Own Data and provide a name for your database and collection. The database name will be required for the configuration above. The collection name is not critical and can be deleted later as Superlinked will create its own.

Creating a Database User and add your IP:

  1. Click on the Database option on the left.

  2. Click the Connect button next to your cluster's name.

  3. In the pop-up window:

    1. Click on the Allow access from Anywhere or select the Add a different IP address and insert your VM's or local IP address.

    2. Enter the username and password for your user. These credentials will be needed for the configuration above.

Creating the API Key:

  1. Click on the Access Manager selector at the top left corner next to your organization selector and select your project.

  2. Go to the API Keys tab.

  3. Provide a name for the API key and select the Project Data Access Admin role in the Project Permissions selector.

  4. Copy the Private Key as it will not be accessible again. The Public key and Private key will be your admin_api_user and admin_api_password in your connection in this order.

Example app with Mongo DB

Extra parameters: extra params can be passed in to the PyMongo client called MongoClient. Please read the for more information.

Navigate to and sign in.

You can find an example that utilizes Mongo DB .

documentation
MongoDB Atlas
here
more information
about the limitation
about the administration API
below
below