File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
rig-integrations/rig-surrealdb/examples Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -78,17 +78,18 @@ async fn main() -> Result<(), anyhow::Error> {
7878 println ! ( "{} results for query: {}" , results. len( ) , query) ;
7979 for ( distance, _id, doc) in results. iter ( ) {
8080 println ! ( "Result distance {distance} for word: {doc}" ) ;
81-
82- // expected output
83- // Result distance 0.693218142100547 for word: glarb-glarb
84- // Result distance 0.2529120980283861 for word: linglingdong
8581 }
8682
87- println ! ( "Attempting vector search with cosine similarity threshold of 0.5 and query: {query}" ) ;
83+ // Use the midpoint as similarity threshold to guarantee exactly one result is returned.
84+ let midpoint = ( results[ 0 ] . 0 + results[ 1 ] . 0 ) / 2.0 ;
85+
86+ println ! (
87+ "Attempting vector search with cosine similarity threshold of {midpoint} and query: {query}"
88+ ) ;
8889 let req = VectorSearchRequest :: builder ( )
8990 . query ( query)
9091 . samples ( 2 )
91- . threshold ( 0.5 )
92+ . threshold ( midpoint )
9293 . build ( ) ?;
9394
9495 let results = vector_store. top_n :: < WordDefinition > ( req) . await ?;
You can’t perform that action at this time.
0 commit comments