Class MongoBindexRepository

java.lang.Object
org.machanism.machai.bindex.core.MongoBindexRepository
All Implemented Interfaces:
BindexRepository

public class MongoBindexRepository extends Object implements BindexRepository
MongoDB-backed repository for persisting and retrieving Bindex documents.

The repository stores the serialized Bindex JSON in a dedicated field (see BINDEX_PROPERTY_NAME) and provides helper operations commonly needed by higher-level components such as Picker and tool integrations.

Connection details are resolved from configuration/environment:

  • When BINDEX_REPO_URL is configured, it is used as the MongoDB connection URI.
  • Otherwise a default cluster URI is used, with credentials optionally sourced from BINDEX_REG_PASSWORD.
Since:
1.2.0
Author:
Viktor Tovstyi
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Configuration property name for the MongoDB password.
    static final String
    MongoDB field name used to store the serialized Bindex JSON payload.
    static final String
    Default MongoDB connection URL used when no repository URL is configured.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a repository instance backed by a MongoDB collection.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the underlying MongoClient if this repository created it.
    deleteBindex(org.machanism.machai.schema.Bindex bindex)
    Deletes a Bindex document from the database.
    find(org.machanism.machai.schema.Classification[] classifications, List<Double> embedding, long vectorSearchLimits, Double score, Configurator config)
    Picks matching Bindex entries for a natural-language query.
    org.machanism.machai.schema.Bindex
    Retrieves a Bindex instance from the database by its Bindex id.
    com.mongodb.client.MongoCollection<org.bson.Document>
    Provides direct access to the underlying MongoDB collection.
    getRegistredId(org.machanism.machai.schema.Bindex bindex)
    Finds the MongoDB registration identifier for the supplied Bindex.
    save(org.machanism.machai.schema.Bindex bindex, List<Double> embedding)
    Registers or replaces a Bindex entry in the repository.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BINDEX_PROPERTY_NAME

      public static final String BINDEX_PROPERTY_NAME
      MongoDB field name used to store the serialized Bindex JSON payload.
      See Also:
    • DB_URL

      public static final String DB_URL
      Default MongoDB connection URL used when no repository URL is configured.
      See Also:
    • BINDEX_PASSWORD_PROP_NAME

      public static final String BINDEX_PASSWORD_PROP_NAME
      Configuration property name for the MongoDB password.
      See Also:
  • Constructor Details

    • MongoBindexRepository

      public MongoBindexRepository(Configurator config)
      Creates a repository instance backed by a MongoDB collection.
      Parameters:
      config - configurator used to resolve BINDEX_REPO_URL
      Throws:
      IllegalArgumentException - if config is null
  • Method Details

    • getCollection

      public com.mongodb.client.MongoCollection<org.bson.Document> getCollection()
      Provides direct access to the underlying MongoDB collection.

      Used by components such as Picker which operate on aggregation pipelines and need the raw MongoCollection.

      Returns:
      the MongoDB collection handle
    • close

      public void close()
      Closes the underlying MongoClient if this repository created it.

      This allows callers to use try-with-resources:

       try (MongoBindexRepository repo = new MongoBindexRepository(config)) { ... }
       
    • getBindex

      public org.machanism.machai.schema.Bindex getBindex(String id)
      Retrieves a Bindex instance from the database by its Bindex id.
      Specified by:
      getBindex in interface BindexRepository
      Parameters:
      id - Bindex id (the id field in the stored document)
      Returns:
      parsed Bindex, or null if not present
      Throws:
      IllegalArgumentException - if id is null or the stored JSON cannot be parsed
    • deleteBindex

      public String deleteBindex(org.machanism.machai.schema.Bindex bindex)
      Deletes a Bindex document from the database.
      Parameters:
      bindex - Bindex to delete (by Bindex.getId())
      Returns:
      the deleted Bindex id
      Throws:
      IllegalArgumentException - if bindex is null
    • save

      public String save(org.machanism.machai.schema.Bindex bindex, List<Double> embedding)
      Registers or replaces a Bindex entry in the repository.
      Specified by:
      save in interface BindexRepository
      Parameters:
      bindex - the Bindex definition to persist
      embedding - the embedding vector associated with the Bindex entry
      Returns:
      the inserted MongoDB identifier as a string
      Throws:
      IllegalArgumentException - if the Bindex or its classification cannot be serialized
    • getRegistredId

      public String getRegistredId(org.machanism.machai.schema.Bindex bindex)
      Finds the MongoDB registration identifier for the supplied Bindex.
      Parameters:
      bindex - the Bindex to look up
      Returns:
      the MongoDB object identifier string, or null if not found
      Throws:
      IllegalArgumentException - if bindex is null
    • find

      public Collection<BindexInfo> find(org.machanism.machai.schema.Classification[] classifications, List<Double> embedding, long vectorSearchLimits, Double score, Configurator config)
      Picks matching Bindex entries for a natural-language query.
      Specified by:
      find in interface BindexRepository
      Parameters:
      classifications - an array of Classification filters to restrict search scope
      embedding - the embedding vector for semantic search
      vectorSearchLimits - the maximum number of results to return from vector search
      score - the minimum relevance score threshold for recommended entries
      config - the configuration object
      Returns:
      the list of matching Bindex entries