Package org.machanism.machai.bindex.core
Class Picker
java.lang.Object
org.machanism.machai.bindex.core.Picker
Performs Bindex registration, lookup, and semantic retrieval using embeddings
and MongoDB.
The Picker class provides methods for:
- Recommending libraries (Bindex entries) based on a natural language prompt and score threshold
- Registering and retrieving Bindex entries
- Building and executing classification prompts using a GenAI provider
- Recursively resolving dependencies for a Bindex entry
- Normalizing language names for repository matching
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringClasspath resource path for the Bindex JSON schema.private BindexRepositoryRepository used for Bindex persistence and semantic search.private static final StringConfiguration property overriding the classification prompt template.private ConfiguratorConfiguration used to select AI and embedding providers.private static final StringDefault prompt template used when no classification instruction is configured.private intNumber of dimensions requested from the embedding provider.private final org.slf4j.LoggerLogger used to report registration and recommendation diagnostics.private static final StringConfiguration property selecting the GenAI model used for classification. -
Constructor Summary
ConstructorsConstructorDescriptionPicker(BindexRepository bindexRepository, Configurator configurator) Creates a Picker backed by the configured Bindex repository and a named GenAI provider. -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddDependencies(Set<String> dependencies, String bindexId) Recursively adds the dependencies of the given Bindex to the provided set.private StringgetClassification(String query, Configurator configurator) Builds a classification prompt from the query and executes it through the configured provider.private StringgetClassificationText(org.machanism.machai.schema.Classification classification) Serializes a classification into JSON text for prompt and embedding generation.getEmbedding(org.machanism.machai.schema.Classification classification) Generates the embedding vector for a classification.(package private) static StringgetNormalizedLanguageName(org.machanism.machai.schema.Language language) Normalizes a language name for repository matching.pick(String prompt, long vectorSearchLimits, double score, Configurator configurator) Recommends a list ofBindexentries based on the provided prompt and minimum score.save(org.machanism.machai.schema.Bindex bindex) Saves aBindexentry to the repository, generating and storing its embedding vector.
-
Field Details
-
logger
private final org.slf4j.Logger loggerLogger used to report registration and recommendation diagnostics. -
BINDEX_SCHEMA_RESOURCE
Classpath resource path for the Bindex JSON schema.- See Also:
-
CLASSIFICATION_INSTRUCTION_PROP_NAME
Configuration property overriding the classification prompt template.- See Also:
-
DEFAULT_CLASSIFICATION_INSTRUCTION
Default prompt template used when no classification instruction is configured.- See Also:
-
MODEL_PROP_NAME
Configuration property selecting the GenAI model used for classification.- See Also:
-
configurator
Configuration used to select AI and embedding providers. -
bindexRepository
Repository used for Bindex persistence and semantic search. -
dimensions
private int dimensionsNumber of dimensions requested from the embedding provider.
-
-
Constructor Details
-
Picker
Creates a Picker backed by the configured Bindex repository and a named GenAI provider.- Parameters:
bindexRepository- the repository used to save and retrieve Bindex dataconfigurator- the project configuration used for repository and prompt settings
-
-
Method Details
-
save
Saves aBindexentry to the repository, generating and storing its embedding vector.- Parameters:
bindex- theBindexobject to save- Returns:
- the unique identifier of the saved
Bindexentry - Throws:
IllegalArgumentException- if the embedding vector generation or JSON serialization fails due to a syntax issue
-
pick
public Collection<BindexInfo> pick(String prompt, long vectorSearchLimits, double score, Configurator configurator) throws IOException Recommends a list ofBindexentries based on the provided prompt and minimum score.This method uses a GenAI provider to classify the prompt, generates an embedding, and queries the Bindex repository for matching entries.
- Parameters:
prompt- the natural language description of project requirementsvectorSearchLimits- the maximum number of results to return from vector searchscore- the minimum relevance score threshold for recommended entriesconfigurator- the configuration object- Returns:
- a list of recommended
Bindexentries matching the criteria - Throws:
IOException- if there is an error during classification or repository access
-
getEmbedding
private List<Double> getEmbedding(org.machanism.machai.schema.Classification classification) throws com.fasterxml.jackson.core.JsonProcessingException Generates the embedding vector for a classification.- Parameters:
classification- the classification to embed- Returns:
- the embedding encoded as a list of doubles
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if the classification cannot be serializedIllegalArgumentException- if the classification is null
-
getClassificationText
private String getClassificationText(org.machanism.machai.schema.Classification classification) throws com.fasterxml.jackson.core.JsonProcessingException Serializes a classification into JSON text for prompt and embedding generation.- Parameters:
classification- the classification to serialize- Returns:
- the serialized JSON representation
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if serialization fails
-
getClassification
Builds a classification prompt from the query and executes it through the configured provider.- Parameters:
query- the natural-language request to classifyconfigurator- the configuration object- Returns:
- the raw provider response containing classification JSON
- Throws:
IOException- if the schema resource cannot be loaded or parsed
-
addDependencies
Recursively adds the dependencies of the given Bindex to the provided set.- Parameters:
dependencies- the target set that accumulates dependency identifiersbindexId- the root Bindex identifier whose dependency graph is traversed
-
getNormalizedLanguageName
Normalizes a language name for repository matching.- Parameters:
language- the language to normalize- Returns:
- the normalized lowercase language name without any parenthetical suffix
-