classifiers.init_tool_embeddings module
Initialize tool embeddings in Redis.
Reads tool definitions and their synthetic queries from
tool_index_data.json, computes centroid embeddings via the
OpenRouter API, and stores them in Redis hashes for fast
vector-based tool selection at runtime.
Usage:
python -m classifiers.init_tool_embeddings [--force]
- Environment variables:
OPENROUTER_API_KEY – required REDIS_URL – defaults to redis://localhost:6379/0
- async classifiers.init_tool_embeddings.main()[source]
Run the tool-embedding initialization as a standalone CLI entry point.
Parses command-line arguments (
--force,--index-file,--redis-url), resolves the index file and Redis connection, then loads the synthetic queries fromtool_index_data.json, computes their centroid embeddings, and stores them as Redis hashes that the runtime vector classifier reads for fast tool selection. This is the second stage of the tool-routing pipeline, afterbuild_tool_indexhas generated the synthetic queries.It opens an async Redis client via
redis.asyncio.from_url(applying TLS kwargs fromconfig.Config.load().redis_ssl_kwargswhen available) and delegates the actual embedding and storage toclassifiers.vector_classifier.initialize_tool_embeddings_from_file(), closing the client in afinallyblock. Progress is logged and the process exits with status0on success or1on a missing index file or initialization failure. Invoked only from this module’s__main__guard viaasyncio.run(run aspython -m classifiers.init_tool_embeddings); no other callers were found.- Return type:
- Returns:
None. The function communicates its outcome by calling
sys.exitwith the appropriate status code rather than returning normally.