Package org.machanism.machai.bindex.core
Class MongoBindexRepository
java.lang.Object
org.machanism.machai.bindex.core.MongoBindexRepository
- All Implemented Interfaces:
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_URLis 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 -
Constructor Summary
ConstructorsConstructorDescriptionMongoBindexRepository(Configurator config) Creates a repository instance backed by a MongoDB collection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the underlyingMongoClientif 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.BindexRetrieves aBindexinstance 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.Registers or replaces a Bindex entry in the repository.
-
Field Details
-
BINDEX_PROPERTY_NAME
MongoDB field name used to store the serialized Bindex JSON payload.- See Also:
-
DB_URL
Default MongoDB connection URL used when no repository URL is configured.- See Also:
-
BINDEX_PASSWORD_PROP_NAME
Configuration property name for the MongoDB password.- See Also:
-
-
Constructor Details
-
MongoBindexRepository
Creates a repository instance backed by a MongoDB collection.- Parameters:
config- configurator used to resolveBINDEX_REPO_URL- Throws:
IllegalArgumentException- ifconfigisnull
-
-
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
Pickerwhich operate on aggregation pipelines and need the rawMongoCollection.- Returns:
- the MongoDB collection handle
-
close
public void close()Closes the underlyingMongoClientif this repository created it.This allows callers to use try-with-resources:
try (MongoBindexRepository repo = new MongoBindexRepository(config)) { ... } -
getBindex
Retrieves aBindexinstance from the database by its Bindex id.- Specified by:
getBindexin interfaceBindexRepository- Parameters:
id- Bindex id (theidfield in the stored document)- Returns:
- parsed
Bindex, ornullif not present - Throws:
IllegalArgumentException- ifidisnullor the stored JSON cannot be parsed
-
deleteBindex
Deletes a Bindex document from the database.- Parameters:
bindex- Bindex to delete (byBindex.getId())- Returns:
- the deleted Bindex id
- Throws:
IllegalArgumentException- ifbindexisnull
-
save
Registers or replaces a Bindex entry in the repository.- Specified by:
savein interfaceBindexRepository- Parameters:
bindex- the Bindex definition to persistembedding- 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
Finds the MongoDB registration identifier for the supplied Bindex.- Parameters:
bindex- the Bindex to look up- Returns:
- the MongoDB object identifier string, or
nullif not found - Throws:
IllegalArgumentException- ifbindexisnull
-
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:
findin interfaceBindexRepository- Parameters:
classifications- an array ofClassificationfilters to restrict search scopeembedding- the embedding vector for semantic searchvectorSearchLimits- the maximum number of results to return from vector searchscore- the minimum relevance score threshold for recommended entriesconfig- the configuration object- Returns:
- the list of matching Bindex entries
-