diff --git a/agents-api/agents_api/autogen/Docs.py b/agents-api/agents_api/autogen/Docs.py index 2472c4b2d..5348add47 100644 --- a/agents-api/agents_api/autogen/Docs.py +++ b/agents-api/agents_api/autogen/Docs.py @@ -153,7 +153,7 @@ class HybridDocSearchRequest(BaseDocSearchRequest): model_config = ConfigDict( populate_by_name=True, ) - confidence: Annotated[float, Field(ge=0.0, le=1.0)] = 0 + confidence: Annotated[float, Field(ge=-1.0, le=1.0)] = 0 """ The confidence cutoff level """ @@ -222,7 +222,7 @@ class VectorDocSearchRequest(BaseDocSearchRequest): model_config = ConfigDict( populate_by_name=True, ) - confidence: Annotated[float, Field(ge=0.0, le=1.0)] = 0 + confidence: Annotated[float, Field(ge=-1.0, le=1.0)] = 0 """ The confidence cutoff level """ diff --git a/integrations-service/integrations/autogen/Docs.py b/integrations-service/integrations/autogen/Docs.py index 2472c4b2d..5348add47 100644 --- a/integrations-service/integrations/autogen/Docs.py +++ b/integrations-service/integrations/autogen/Docs.py @@ -153,7 +153,7 @@ class HybridDocSearchRequest(BaseDocSearchRequest): model_config = ConfigDict( populate_by_name=True, ) - confidence: Annotated[float, Field(ge=0.0, le=1.0)] = 0 + confidence: Annotated[float, Field(ge=-1.0, le=1.0)] = 0 """ The confidence cutoff level """ @@ -222,7 +222,7 @@ class VectorDocSearchRequest(BaseDocSearchRequest): model_config = ConfigDict( populate_by_name=True, ) - confidence: Annotated[float, Field(ge=0.0, le=1.0)] = 0 + confidence: Annotated[float, Field(ge=-1.0, le=1.0)] = 0 """ The confidence cutoff level """ diff --git a/memory-store/migrations/000022_vector_search.up.sql b/memory-store/migrations/000022_vector_search.up.sql index 53cefcf4e..40866f920 100644 --- a/memory-store/migrations/000022_vector_search.up.sql +++ b/memory-store/migrations/000022_vector_search.up.sql @@ -6,7 +6,7 @@ CREATE OR REPLACE FUNCTION search_by_vector ( owner_types TEXT[], owner_ids UUID [], k integer DEFAULT 3, - confidence float DEFAULT 0.5, + confidence float DEFAULT 0.0, metadata_filter jsonb DEFAULT NULL ) RETURNS SETOF doc_search_result LANGUAGE plpgsql AS $$ DECLARE @@ -19,8 +19,8 @@ BEGIN RAISE EXCEPTION 'k must be greater than 0'; END IF; - IF confidence < 0 OR confidence > 1 THEN - RAISE EXCEPTION 'confidence must be between 0 and 1'; + IF confidence < -1 OR confidence > 1 THEN + RAISE EXCEPTION 'confidence must be between -1 and 1'; END IF; IF owner_types IS NOT NULL AND owner_ids IS NOT NULL AND @@ -29,7 +29,7 @@ BEGIN END IF; -- Calculate search threshold from confidence - search_threshold := confidence; + search_threshold := 1.0 - confidence; -- Build owner filter SQL owner_filter_sql := ' @@ -53,7 +53,7 @@ BEGIN d.index, d.title, d.content, - ((1 - (d.embedding <=> $1)) + 1) * 0.5 as distance, + (d.embedding <=> $1) as distance, d.embedding, d.metadata, doc_owners.owner_type, @@ -61,15 +61,15 @@ BEGIN FROM docs_embeddings d LEFT JOIN doc_owners ON d.doc_id = doc_owners.doc_id WHERE d.developer_id = $7 - AND ((1 - (d.embedding <=> $1)) + 1) * 0.5 >= $2 + AND (d.embedding <=> $1) <= $2 %s %s - ORDER BY ((1 - (d.embedding <=> $1)) + 1) * 0.5 DESC + ORDER BY (d.embedding <=> $1) ASC LIMIT ($3 * 4) -- Get more candidates than needed ) SELECT DISTINCT ON (doc_id) * FROM ranked_docs - ORDER BY doc_id, distance DESC + ORDER BY doc_id, distance ASC LIMIT $3', owner_filter_sql, metadata_filter_sql diff --git a/typespec/docs/models.tsp b/typespec/docs/models.tsp index 6310b42c5..5418cafd9 100644 --- a/typespec/docs/models.tsp +++ b/typespec/docs/models.tsp @@ -125,7 +125,7 @@ model BaseDocSearchRequest { model VectorDocSearchRequest extends BaseDocSearchRequest { /** The confidence cutoff level */ - @minValue(0) + @minValue(-1) @maxValue(1) confidence: float = 0; @@ -146,7 +146,7 @@ model TextOnlyDocSearchRequest extends BaseDocSearchRequest { model HybridDocSearchRequest extends BaseDocSearchRequest { /** The confidence cutoff level */ - @minValue(0) + @minValue(-1) @maxValue(1) confidence: float = 0; diff --git a/typespec/tsp-output/@typespec/openapi3/openapi-1.0.0.yaml b/typespec/tsp-output/@typespec/openapi3/openapi-1.0.0.yaml index 8861ae9cd..5906ce6a9 100644 --- a/typespec/tsp-output/@typespec/openapi3/openapi-1.0.0.yaml +++ b/typespec/tsp-output/@typespec/openapi3/openapi-1.0.0.yaml @@ -2983,7 +2983,7 @@ components: properties: confidence: type: number - minimum: 0 + minimum: -1 maximum: 1 description: The confidence cutoff level default: 0 @@ -3066,7 +3066,7 @@ components: properties: confidence: type: number - minimum: 0 + minimum: -1 maximum: 1 description: The confidence cutoff level default: 0