Class Picker
java.lang.Object
org.machanism.machai.bindex.core.Picker
Performs Bindex registration, lookup, and semantic retrieval through a
BindexRepository using GenAI-derived classifications and embeddings.
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 static StringLazily initialized cache holding the extracted classification JSON schema fragment to avoid repeated resource reads.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.private static final com.fasterxml.jackson.databind.ObjectMapperShared JSON mapper used to read the schema and serialize schema nodes. -
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 for a user query and obtains the provider's response.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.private static StringLoads and caches the classification portion of the Bindex JSON schema.pick(String prompt, long vectorSearchLimits, double score, Configurator configurator) Recommends a list ofBindexentries based on the provided prompt and minimum score.private static StringreadResource(Class<?> owner, String path) Reads a UTF-8 classpath resource without using the URL connection cache.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:
-
OBJECT_MAPPER
private static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPERShared JSON mapper used to read the schema and serialize schema nodes. -
classificationSchemaCache
Lazily initialized cache holding the extracted classification JSON schema fragment to avoid repeated resource reads. -
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
-
readResource
Reads a UTF-8 classpath resource without using the URL connection cache.- Parameters:
owner- the class used to resolve the resource pathpath- the classpath resource path to read- Returns:
- the resource contents as a UTF-8 string
- Throws:
IOException- if the resource cannot be found or read
-
loadClassificationSchema
Loads and caches the classification portion of the Bindex JSON schema.- Returns:
- the classification schema serialized as JSON
- Throws:
IOException- if the schema resource cannot be read or does not contain the expected classification property
-
getClassification
Builds a classification prompt for a user query and obtains the provider's response.- Parameters:
query- the natural-language request to classifyconfigurator- the configuration used to resolve the prompt template and GenAI provider- Returns:
- the provider-generated classification response
- Throws:
IOException- if the classification schema cannot be loadedIllegalArgumentException- if the configured prompt template is invalid or no GenAI model is configured
-
addDependencies
-
getNormalizedLanguageName
Normalizes a language name for repository matching.- Parameters:
language- the language to normalize- Returns:
- the normalized lowercase language name without any parenthetical suffix
-