Some checks failed
CI / build-and-test (push) Failing after -32m22s
* Implement tests for migrating configuration from v1 to v2 for the litellm provider. * Validate the structure and values of the migrated configuration. * Ensure migration rejects newer versions of the configuration. fix(validate): enhance AI provider validation logic * Consolidate provider validation into a dedicated method. * Ensure at least one provider is specified and validate its type. * Check for required fields based on provider type. fix(mcpserver): update tool set to use new enrichment tool * Replace RetryMetadataTool with RetryEnrichmentTool in the ToolSet. fix(tools): refactor tools to use embedding and metadata runners * Update tools to utilize EmbeddingRunner and MetadataRunner instead of Provider. * Adjust method calls to align with the new runner interfaces.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"git.warky.dev/wdevs/amcs/internal/ai"
|
|
"git.warky.dev/wdevs/amcs/internal/config"
|
|
"git.warky.dev/wdevs/amcs/internal/store"
|
|
thoughttypes "git.warky.dev/wdevs/amcs/internal/types"
|
|
)
|
|
|
|
// semanticSearch runs vector similarity search if embeddings exist for the
|
|
// primary embedding model in the given scope, otherwise falls back to Postgres
|
|
// full-text search. Search always uses the primary model so query vectors
|
|
// match rows stored under the primary model name.
|
|
func semanticSearch(
|
|
ctx context.Context,
|
|
db *store.DB,
|
|
embeddings *ai.EmbeddingRunner,
|
|
search config.SearchConfig,
|
|
query string,
|
|
limit int,
|
|
threshold float64,
|
|
projectID *uuid.UUID,
|
|
excludeID *uuid.UUID,
|
|
) ([]thoughttypes.SearchResult, error) {
|
|
model := embeddings.PrimaryModel()
|
|
hasEmbeddings, err := db.HasEmbeddingsForModel(ctx, model, projectID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if hasEmbeddings {
|
|
embedding, err := embeddings.EmbedPrimary(ctx, query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return db.SearchSimilarThoughts(ctx, embedding, model, threshold, limit, projectID, excludeID)
|
|
}
|
|
|
|
return db.SearchThoughtsText(ctx, query, limit, projectID, excludeID)
|
|
}
|