Package org.machanism.machai.bindex
Class Picker
java.lang.Object
org.machanism.machai.bindex.Picker
- All Implemented Interfaces:
Closeable,AutoCloseable
Picker handles Bindex registration, lookup, and semantic queries using
embeddings and MongoDB.
Provides registration and query operations for Bindex repositories, supporting classification embedding for semantic retrieval and indexing.
Usage example:
try (Picker picker = new Picker(provider)) {
List<Bindex> results = picker.pick("search query");
}
- Since:
- 0.0.2
- Author:
- Viktor Tovstyi
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddDependencies(Set<String> dependencies, String bindexId) Adds all transitive dependencies of a Bindex into the provided set.voidclose()Closes the resource-backed connections.Registers (inserts or updates) a Bindex document for the supplied Bindex instance.(package private) org.bson.BsonArraygetEmbeddingBson(Classification classification, Integer dimensions) Generates a BSON array representing the embedding of a classification for semantic search.(package private) static StringgetNormalizedLanguageName(Language language) Normalizes a Language name for semantic aggregation queries.getRegistredId(Bindex bindex) Looks up the registered database ID for a Bindex (if it exists).Retrieves similarity score for a Bindex result by its ID.Performs a semantic pick/search with a query string, retrieving Bindex results and dependencies.voidManually set minimum score for semantic vector search queries.
-
Field Details
-
DEFAULT_MIN_SCORE
Default minimum similarity score for queries.- See Also:
-
BINDEX_PROPERTY_NAME
- See Also:
-
-
Constructor Details
-
Picker
Constructs a Picker for registration and semantic search.- Parameters:
provider- GenAIProvider instance used for embedding, schema classification, etc.uri-- Throws:
IllegalStateException- If the required environment variables are missing for DB or OpenAI access
-
-
Method Details
-
close
Closes the resource-backed connections.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if closing the MongoDB client fails
-
create
Registers (inserts or updates) a Bindex document for the supplied Bindex instance.- Parameters:
bindex- Bindex instance to register- Returns:
- Generated database ID string
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If conversion to JSON string fails or MongoDB throws exceptioncom.mongodb.MongoCommandException- On MongoDB insert or connection errors
-
getEmbeddingBson
org.bson.BsonArray getEmbeddingBson(Classification classification, Integer dimensions) throws com.fasterxml.jackson.core.JsonProcessingException Generates a BSON array representing the embedding of a classification for semantic search.- Parameters:
classification- Classification instancedimensions- Number of vector dimensions- Returns:
- BsonArray of vector values
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- On embedding or serialization errors
-
getRegistredId
-
pick
Performs a semantic pick/search with a query string, retrieving Bindex results and dependencies.- Parameters:
query- Query string- Returns:
- List of Bindex results related to the query (and their dependencies)
- Throws:
IOException- If prompt or IO operation fails
-
addDependencies
-
getNormalizedLanguageName
-
setScore
Manually set minimum score for semantic vector search queries.- Parameters:
score- Minimum similarity value
-
getScore
-