Class Picker

java.lang.Object
org.machanism.machai.bindex.Picker

public class Picker extends Object
Performs Bindex registration, lookup, and semantic retrieval using embeddings and MongoDB.
  • Field Details

  • Constructor Details

    • Picker

      public Picker(String genai, String uri, Configurator config)
      Creates a picker backed by the configured Bindex repository and a named GenAI provider.
      Parameters:
      genai - the provider identifier used to resolve the GenAI implementation
      uri - the repository URI
      config - the project configuration used for repository and prompt settings
    • Picker

      Picker(com.mongodb.client.MongoCollection<org.bson.Document> collection, org.machanism.machai.ai.provider.Genai provider)
      Creates a picker with explicit dependencies.
      Parameters:
      collection - the MongoDB collection used to store and query Bindex documents
      provider - the GenAI provider used for prompt execution and embeddings
  • Method Details

    • create

      public String create(Bindex bindex) throws com.fasterxml.jackson.core.JsonProcessingException
      Registers or replaces a Bindex entry in the repository.
      Parameters:
      bindex - the Bindex definition to persist
      Returns:
      the inserted MongoDB identifier as a string
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the Bindex or its classification cannot be serialized
    • getEmbeddingBson

      org.bson.BsonArray getEmbeddingBson(Classification classification, int dimensions) throws com.fasterxml.jackson.core.JsonProcessingException
      Generates the BSON array representation of the embedding for a classification.
      Parameters:
      classification - the classification to embed
      dimensions - the embedding dimensions requested from the provider
      Returns:
      the embedding encoded as a BSON array
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if the classification cannot be serialized
    • getRegistredId

      public String getRegistredId(Bindex bindex)
      Finds the MongoDB registration identifier for the supplied Bindex.
      Parameters:
      bindex - the Bindex to look up
      Returns:
      the MongoDB object identifier string, or null if not found
    • pick

      public List<Bindex> pick(String query) throws IOException
      Picks matching Bindex entries for a natural-language query.
      Parameters:
      query - the user request to classify and resolve
      Returns:
      the list of matching Bindex entries
      Throws:
      IOException - if classification generation or JSON parsing fails
    • addDependencies

      void addDependencies(Set<String> dependencies, String bindexId)
      Recursively adds the dependencies of the given Bindex to the provided set.
      Parameters:
      dependencies - the target set that accumulates dependency identifiers
      bindexId - the root Bindex identifier whose dependency graph is traversed
    • getBindex

      protected Bindex getBindex(String id)
      Retrieves a Bindex by its logical identifier.
      Parameters:
      id - the Bindex identifier
      Returns:
      the deserialized Bindex, or null if no entry exists
    • getNormalizedLanguageName

      static String getNormalizedLanguageName(Language language)
      Normalizes a language name for repository matching.
      Parameters:
      language - the language to normalize
      Returns:
      the normalized lowercase language name without any parenthetical suffix
    • setScore

      public void setScore(Double minScore)
      Sets the minimum vector-search score accepted by this picker.
      Parameters:
      minScore - the minimum score threshold
    • getScore

      public Double getScore(String id)
      Returns the last recorded score for a Bindex identifier.
      Parameters:
      id - the Bindex identifier
      Returns:
      the recorded score, or null if none is available