Returns documents most similar to the query along with relevance scores.
Embedded
Python SDK
JS/TS
similarity_search_with_score(
query: str ,
k: int = 4 ,
filter : Optional[Dict[ str , Any]] = None ,
** kwargs
) -> List[Tuple[Document, float ]]
Parameters Parameter Type Description querystrQuery text to search for kintNumber of documents to return (default: 4) filterOptional[Dict[str, Any]](Optional) Metadata filters to apply**kwargsAnyAdditional keyword arguments (currently unused)
Returns List[Tuple[Document, float]]: List of (Document, score) tuples where score is normalized [0, 1]Example Usage # Search with scores
results = store.similarity_search_with_score( "neural networks" , k = 3 )
for doc, score in results:
print ( f "Score: { score :.4f} " )
print ( f "Content: { doc.page_content[: 100 ] } ..." )
print ( f "Metadata: { doc.metadata } " )
print ( "---" )
# Filter results by score threshold
threshold = 0.7
high_score_results = [
(doc, score) for doc, score in results if score >= threshold
]
_similarity_search_with_relevance_scores (internal method)
The Embedded library also exposes _similarity_search_with_relevance_scores, an internal method that supports a score_threshold keyword argument for server-side score filtering: _similarity_search_with_relevance_scores(
query: str ,
k: int ,
** kwargs
) -> List[Tuple[Document, float ]]
Keyword Arguments: Parameter Type Description filterDict[str, Any](Optional) Metadata filters to applyscore_thresholdfloat(Optional) Minimum score threshold for results
Example: # Search with relevance scores and threshold
results = store._similarity_search_with_relevance_scores(
"machine learning" ,
k = 10 ,
score_threshold = 0.5
)
print ( f "Found { len (results) } documents above threshold" )
for doc, score in results:
print ( f "Relevance: { score :.2%} - { doc.page_content[: 50 ] } ..." )
similarity_search_with_score(
query: str ,
k: Optional[ int ] = None ,
filter : Optional[Dict[ str , Any]] = None ,
** kwargs
) -> List[Tuple[Document, float ]]
Parameters Parameter Type Description querystrQuery text to search for kOptional[int](Optional) Number of documents to return (default: None, uses server default)filterOptional[Dict[str, Any]](Optional) Metadata filters to apply**kwargsAnyAdditional keyword arguments
Returns List[Tuple[Document, float]]: List of (Document, score) tuples where score is normalized [0, 1]Example Usage results = store.similarity_search_with_score( "neural networks" , k = 3 )
for doc, score in results:
print ( f "Score: { score :.4f} - { doc.page_content[: 100 ] } ..." )
similaritySearchWithScore (
query : string ,
k ?: number ,
filter ?: Record < string , any >
): Promise < [ Document , number ][] >
Parameters Parameter Type Description querystringQuery text to search for knumber(Optional) Number of documents to returnfilterRecord<string, any>(Optional) Metadata filters to apply
Returns Promise<[Document, number][]>: Array of [Document, score] tuplesExample Usage const results = await store . similaritySearchWithScore ( "neural networks" , 3 );
for ( const [ doc , score ] of results ) {
console . log ( `Score: ${ score . toFixed ( 4 ) } ` );
console . log ( `Content: ${ doc . pageContent . slice ( 0 , 100 ) } ...` );
}
Async
The Embedded and Python SDK provide async versions of this method prefixed with a: # asimilarity_search_with_score — async variant
results = await store.asimilarity_search_with_score( "query" , k = 3 )
JS/TS methods are natively async — all signatures above already return Promise<...>. No separate async variant is needed.