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
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration property name for the MongoDB password.private static final StringMongoDB field containing the serialized Bindex payload.static final StringMongoDB field name used to store the serialized Bindex JSON payload.private static final StringConfiguration property containing the MongoDB connection URL.private static final StringConfiguration property containing a MongoDB username.private static final StringMongoDB field containing the classification embedding vector.private final com.mongodb.client.MongoCollection<org.bson.Document>MongoDB collection containing the persisted Bindex documents.private ConfiguratorConfiguration used to resolve MongoDB connection properties.private static final StringMongoDB collection name.static final StringDefault MongoDB connection URL used when no repository URL is configured.private static final StringMongoDB field containing the Bindex description.private static final StringMongoDB field containing Bindex domains.private static final StringMongoDB field containing the Bindex identifier.private static final StringName of the MongoDB vector-search index.private static final StringMongoDB database name.private static final StringMongoDB field containing normalized integrations.private static final StringMongoDB field containing normalized programming languages.private static final StringMongoDB field containing Bindex architectural layers.private final org.slf4j.LoggerLogger used for repository diagnostics and registration warnings.private com.mongodb.client.MongoClientMongoDB client owned by this repository instance.private static final StringMongoDB field containing the Bindex name.private static final StringDefault username used for the public database connection.private static final StringUsername used for the registration database connection.private static final StringAggregation field containing the vector-search relevance score.private static final StringMongoDB field containing the Bindex version. -
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.private voidInitializes the internalMongoClientinstance.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.(package private) org.bson.DocumentfindFirst(org.bson.conversions.Bson filter) Querying the first matching document based on a Bson filter.(package private) org.bson.DocumentfindFirst(org.bson.Document filter) Querying the first matching document based on a raw Document filter.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.private Map<String,BindexInfo> getResults(List<Double> embedding, Double score, long vectorSearchLimits, org.bson.conversions.Bson... bsons) Executes a vector search and returns matching library coordinates in mapped structure.Registers or replaces a Bindex entry in the repository.
-
Field Details
-
logger
private final org.slf4j.Logger loggerLogger used for repository diagnostics and registration warnings. -
mongoClient
private com.mongodb.client.MongoClient mongoClientMongoDB client owned by this repository instance. -
BINDEX_PROPERTY_NAME
MongoDB field name used to store the serialized Bindex JSON payload.- See Also:
-
CLASSIFICATION_EMBEDDING_PROP_NAME
MongoDB field containing the classification embedding vector.- See Also:
-
LANGUAGES_PROP_NAME
MongoDB field containing normalized programming languages.- See Also:
-
DOMAINS_PROP_NAME
MongoDB field containing Bindex domains.- See Also:
-
LAYERS_PROP_NAME
MongoDB field containing Bindex architectural layers.- See Also:
-
INTEGRATIONS_PROP_NAME
MongoDB field containing normalized integrations.- See Also:
-
BINDEX_PROP_NAME
MongoDB field containing the serialized Bindex payload.- See Also:
-
ID_FIELD_NAME
MongoDB field containing the Bindex identifier.- See Also:
-
NAME_FIELD_NAME
MongoDB field containing the Bindex name.- See Also:
-
VERSION_FIELD_NAME
MongoDB field containing the Bindex version.- See Also:
-
DESCRIPTION_FIELD_NAME
MongoDB field containing the Bindex description.- See Also:
-
SCORE_FIELD_NAME
Aggregation field containing the vector-search relevance score.- See Also:
-
INDEXNAME
Name of the MongoDB vector-search index.- See Also:
-
DB_URL
Default MongoDB connection URL used when no repository URL is configured.- See Also:
-
PUBLILC_USER_NAME
Default username used for the public database connection.- See Also:
-
REGISTER_USER_NAME
Username used for the registration database connection.- See Also:
-
INSTANCENAME
MongoDB database name.- See Also:
-
CONNECTION
MongoDB collection name.- See Also:
-
BINDEX_USER_PROP_NAME
Configuration property containing a MongoDB username.- See Also:
-
BINDEX_PASSWORD_PROP_NAME
Configuration property name for the MongoDB password.- See Also:
-
BINDEX_REPO_URL_PROP_NAME
Configuration property containing the MongoDB connection URL.- See Also:
-
config
Configuration used to resolve MongoDB connection properties. -
collection
private final com.mongodb.client.MongoCollection<org.bson.Document> collectionMongoDB collection containing the persisted Bindex documents.
-
-
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
-
createMongoClient
private void createMongoClient()Initializes the internalMongoClientinstance.Resolves connection details from the provided
Configurator, building a authenticated or public URL to connect to the MongoDB instance. -
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
-
findFirst
org.bson.Document findFirst(org.bson.conversions.Bson filter) Querying the first matching document based on a Bson filter.- Parameters:
filter- the Bson filter to match- Returns:
- the first matching
Document, ornullif none match
-
findFirst
org.bson.Document findFirst(org.bson.Document filter) Querying the first matching document based on a raw Document filter.- Parameters:
filter- the Document filter to match- Returns:
- the first matching
Document, ornullif none match
-
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
-
getResults
private Map<String,BindexInfo> getResults(List<Double> embedding, Double score, long vectorSearchLimits, org.bson.conversions.Bson... bsons) Executes a vector search and returns matching library coordinates in mapped structure.- Parameters:
embedding- the query vector embedding to match againstscore- the minimum vector search score to filter resultsvectorSearchLimits- the maximum size limit of matching elementsbsons- optional aggregation stages appended after vector search- Returns:
- a map of unique library coordinates using the preferred version
-