Documentation
¶
Overview ¶
Package toolstore implements a SQLite-based ToolStore for search over MCP tool metadata. It uses FTS5 for full-text search and optional embedding-based semantic search for hybrid retrieval.
Index ¶
Constants ¶
const ( // DefaultMaxToolsToReturn is the maximum number of results returned to the caller. DefaultMaxToolsToReturn = 8 // DefaultHybridSemanticToolsRatio controls the proportion of semantic vs FTS5 // results in hybrid mode: 0 = all FTS5, 1 = all semantic. DefaultHybridSemanticToolsRatio = 0.5 // DefaultSemanticDistanceThreshold is the maximum cosine distance for semantic search results. // Results with distance > threshold are filtered out in searchSemantic only. // Cosine distance: 0 = identical, 2 = opposite. DefaultSemanticDistanceThreshold = 1.0 )
Default values for configurable search parameters.
Variables ¶
This section is empty.
Functions ¶
func NewSQLiteToolStore ¶
func NewSQLiteToolStore( embeddingClient types.EmbeddingClient, cfg *types.OptimizerConfig, opts ...Option, ) (types.ToolStore, error)
NewSQLiteToolStore creates a new ToolStore backed by a shared in-memory SQLite database. All callers of this constructor share the same database, which is the intended production behavior (one shared store per server). If embeddingClient is non-nil, semantic search is enabled alongside FTS5. If cfg is non-nil, its search parameters override the defaults; nil values use defaults.
Types ¶
type EmbeddingCache ¶ added in v0.70.0
type EmbeddingCache interface {
// GetEmbeddings returns the stored vectors among keys; absent keys are
// omitted. A value longer than maxSharedEmbeddingBytes may be returned
// truncated, one byte past the cap.
GetEmbeddings(ctx context.Context, keys []string) (map[string][]byte, error)
// PutEmbeddings stores each vector under its key.
PutEmbeddings(ctx context.Context, entries map[string][]byte) error
// Close releases the cache's connections. It may be called more than once.
Close() error
}
EmbeddingCache holds encoded tool embeddings outside the process, keyed by embedding cache key (see embeddingCacheKey). A key names the embedded text and the backend identity, so its vector is valid wherever it was computed.
func NewRedisEmbeddingCache ¶ added in v0.70.0
func NewRedisEmbeddingCache(ctx context.Context, cfg redisconn.Config, keyPrefix string) (EmbeddingCache, error)
NewRedisEmbeddingCache connects to Redis and returns an EmbeddingCache that stores each vector as a raw value under keyPrefix + "optimizer:embedding:" + key. keyPrefix must end with ':'. The caller must call Close when done.
type Option ¶ added in v0.70.0
type Option func(*sqliteToolStore)
Option configures a tool store.
func WithEmbeddingCache ¶ added in v0.70.0
func WithEmbeddingCache(cache EmbeddingCache) Option
WithEmbeddingCache shares the store's verified embeddings through cache, so a replica reuses vectors other replicas computed. It shares vectors only: each replica keeps its own rows and index, and replicas that miss the same vectors at the same moment both embed them. A build reads cache at most once, before it waits for the embedding turn, and writes it at most once, after it commits and gives the turn back, so a slow cache delays only that build. A cache failure costs reuse and never fails a build. The store closes cache when it is closed.