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 from tool_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, after build_tool_index has generated the synthetic queries.

It opens an async Redis client via redis.asyncio.from_url (applying TLS kwargs from config.Config.load().redis_ssl_kwargs when available) and delegates the actual embedding and storage to classifiers.vector_classifier.initialize_tool_embeddings_from_file(), closing the client in a finally block. Progress is logged and the process exits with status 0 on success or 1 on a missing index file or initialization failure. Invoked only from this module’s __main__ guard via asyncio.run (run as python -m classifiers.init_tool_embeddings); no other callers were found.

Return type:

None

Returns:

None. The function communicates its outcome by calling sys.exit with the appropriate status code rather than returning normally.