Class BindexFunctionTools
- All Implemented Interfaces:
FunctionTools
FunctionTools that provides
discovery, resolution, and registration actions for Bindex components to
large language models (LLMs).
This class exposes annotated Tool, Prompt, Resource,
and Param capabilities for AI agents to interact with Bindex
repositories. Its functional AI tools are get_bindex, which retrieves
metadata; pick_libraries, which recommends libraries;
register_bindex, which registers a descriptor from a file or URL; and
register_bindex_json, which registers a supplied descriptor. It also
provides the generate-bindex prompt template and the
file:///schema/bindex-schema-v2.json contextual JSON Schema resource.
Key capabilities include:
- Discovery & Recommendation: Finding relevant libraries based on natural language project descriptions.
- Metadata Extraction: Querying comprehensive library descriptions and schemas via specific IDs.
- Descriptor Registration: Adding or updating library declarations from direct JSON objects, local project files, or remote URLs.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringDefault file name for the Bindex JSON metadata file.private static final StringURL to the official Bindex JSON schema definition.private BindexRepositoryRepository instance for accessing and managing Bindex records.private static final StringThe default similarity score threshold used to filter out low-confidence search results during vector search queries.static final StringProperty name for specifying the model to use in configuration.private static final StringDefault limit for the number of results returned by vector search operations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPrompt Template namedgenerate-bindexthat loads and returns the Markdown instructions and contextual prompts required for Bindex file generation.org.machanism.machai.schema.BindexgetBindex(String id, String query, File projectDir, Configurator configurator) Functional AI Tool that retrieves Bindex metadata for a given project or library.private BindexRepositorygetBindexRepository(Configurator configurator) Returns the currentBindexRepositoryinstance, initializing it if necessary.getBindexSchema(URI uri) Contextual Resource that retrieves the JSON Schema definition for Bindex (bundle index) validation.getRecommendedLibraries(String prompt, double score, int vectorSearchLimits, Configurator configurator) Functional AI Tool that recommends libraries based on the user's prompt or project requirements.registerBindex(String path, File projectDir, Configurator configurator) Functional AI Tool that registers a Bindex JSON object from a file in the project directory or a directhttp://orhttps://URL.registerBindexJson(org.machanism.machai.schema.Bindex bindex, Configurator configurator) Functional AI Tool that registers a Bindex JSON object and returns its Bindex ID on successful registration.(package private) FileresolveProjectFile(String path, File projectDir) Resolves a descriptor and ensures that it remains within the project tree.
-
Field Details
-
BINDEX_SCHEMA
URL to the official Bindex JSON schema definition. Used for validating Bindex files and ensuring schema compliance.- See Also:
-
VECTOR_SEARCH_LIMITS
Default limit for the number of results returned by vector search operations.- See Also:
-
DEFAULT_SCORE_VALUE
The default similarity score threshold used to filter out low-confidence search results during vector search queries. Only results with a cosine similarity score greater than or equal to this value will be returned.Range: [0.0, 1.0] where 1.0 is an exact semantic match. Default:
0.85- See Also:
-
BINDEX_JSON_FILE_NAME
Default file name for the Bindex JSON metadata file.- See Also:
-
MODEL_PROP_NAME
Property name for specifying the model to use in configuration.- See Also:
-
bindexRepository
Repository instance for accessing and managing Bindex records.
-
-
Constructor Details
-
BindexFunctionTools
public BindexFunctionTools()Creates a new Bindex function tool set.
-
-
Method Details
-
getBindex
public org.machanism.machai.schema.Bindex getBindex(String id, String query, File projectDir, Configurator configurator) throws IOException Functional AI Tool that retrieves Bindex metadata for a given project or library.The
idparameter accepts standard Bindex coordinates, a directhttp://orhttps://URL for a remote descriptor, or afile://path for local JSON parsing and validation. Relative file paths are resolved againstprojectDir; all other identifiers are resolved through the configured repository.If a GraphQL query is provided via the
graphql_queryparameter, the resultingBindexobject's JSON representation will be filtered to include only the requested fields before being returned.- Parameters:
id- The unique Bindex identifier (for example,groupId:artifactId:version), a directhttp://orhttps://Bindex JSON URL, or afile://path; must not benull.query- An optional GraphQL-style query to filter the response payload fields and minimize token consumption (e.g.,"{ name version classification { languages } }").projectDir- The base directory used to resolve a relativefile://descriptor path; required for relative file paths and otherwise may benull.configurator- The repository configuration used whenidis a Bindex identifier.- Returns:
- The complete
Bindex, or a deserialized projection whenqueryis supplied. - Throws:
IOException- If the remote descriptor cannot be read or serialized.IllegalArgumentException- If no Bindex is found for an identifier.
-
getBindexRepository
Returns the currentBindexRepositoryinstance, initializing it if necessary.If the repository has not yet been created, this method instantiates a new
MongoBindexRepositoryusing the supplied configuration. The same instance is returned on subsequent calls.- Parameters:
configurator- the configuration used when a repository must be initialized- Returns:
- the
BindexRepositoryinstance
-
getRecommendedLibraries
public Collection<BindexInfo> getRecommendedLibraries(String prompt, double score, int vectorSearchLimits, Configurator configurator) throws IOException Functional AI Tool that recommends libraries based on the user's prompt or project requirements.- Parameters:
prompt- A description of your project needs or requirements. For example, specify the functionality, technology stack, or features you want to implement.score- The minimum relevance score threshold for recommended libraries. Only libraries with a score equal to or higher than this value are included; the tool metadata defaults it to0.85.vectorSearchLimits- The maximum number of recommendations to retrieve from vector search. The value is passed to the configured picker as the result limit; the tool metadata defaults it to25.configurator- The configuration used to create the repository and picker.- Returns:
- A collection of
BindexInfoobjects representing recommended libraries. - Throws:
IOException- If there is an error during recommendation.
-
registerBindex
public String registerBindex(String path, File projectDir, Configurator configurator) throws IOException Functional AI Tool that registers a Bindex JSON object from a file in the project directory or a directhttp://orhttps://URL. On success it returns the Bindex ID and adds or updates the metadata available to library search and integration.- Parameters:
path- The Bindex file path, which must exist within the project directory, or a direct HTTP(S) URL. The tool metadata defaults it tobindex.json.projectDir- The project directory; required for file registration.configurator- The configuration used to create the repository and picker.- Returns:
- The unique record ID assigned by the configured picker.
- Throws:
FileNotFoundException- If the specified file does not exist.IOException- If there is an error reading the file.IllegalArgumentException- IfprojectDiris absent for a file-based registration, or an absolute path lies outside that directory.
-
resolveProjectFile
Resolves a descriptor and ensures that it remains within the project tree.- Parameters:
path- the user-provided descriptor pathprojectDir- the trusted project base directory- Returns:
- the canonical descriptor file
- Throws:
IOException- if a path cannot be canonicalizedIllegalArgumentException- if the base directory is absent or the descriptor is outside it
-
registerBindexJson
public String registerBindexJson(org.machanism.machai.schema.Bindex bindex, Configurator configurator) Functional AI Tool that registers a Bindex JSON object and returns its Bindex ID on successful registration.- Parameters:
bindex- The Bindex JSON object to register; must not benull.configurator- The configuration used to create the repository and picker.- Returns:
- The unique Bindex ID assigned to the registered entry.
- Throws:
NullPointerException- Ifbindexisnull.
-
getBindexSchema
Contextual Resource that retrieves the JSON Schema definition for Bindex (bundle index) validation.This method loads the
file:///schema/bindex-schema-v2.jsonresource from the classpath and returns its content as a UTF-8 encodedapplication/jsonstring. The supplied URI is the contextual resource URI provided by the tool framework.- Parameters:
uri- the resource URI supplied by the tool framework; its path is used to locate the schema on the classpath- Returns:
- the JSON Schema content for Bindex v2
- Throws:
IOException- if the schema resource cannot be readNullPointerException- if the configured schema resource is absent from the classpath
-
bindexGenerationPrompts
Prompt Template namedgenerate-bindexthat loads and returns the Markdown instructions and contextual prompts required for Bindex file generation.This method reads the prompt template from the classpath resource
/prompts/generate_bindex.mdand returns it as a UTF-8 encoded string.- Returns:
- the content of the Bindex generation prompt template
- Throws:
IOException- if the prompt template resource cannot be readNullPointerException- if the prompt template resource is absent from the classpath
-