ElasticSearch Langchain retreive embedding based on particular threshold

why similarity_score_threshold is not working. When i changed search_type to similarity then it is worked but retreiverdocument not based on score threshold.

retriever = db.as_retriever(
search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.5}
)
docs = retriever.get_relevant_documents(query)

Hi!

Do you have some more information about your example and how it's not working?

I just tested it in one of my projects and it seems to run for me.

When the threshold is 0.5 I get the same results with the threshold as with the normal similarity. With a higher threshold, some results are omited, and for example, if I increase the threshold too much I get this back: UserWarning: No relevant docs were retrieved using the relevance score threshold 0.8 so it seems to be taking the threshold into account.

This is the rest of my code FYI:

db = ElasticsearchStore(
    index_name=index_name,
    es_connection=es_connection,
    query_field="text_field",
    vector_query_field="vector_query_field.predicted_value",
    strategy=ElasticsearchStore.ApproxRetrievalStrategy(
        query_model_id=model_id
    ),
)

db.client.indices.refresh(index=index_name)

retriever = db.as_retriever(
search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.7}
)

docs = retriever.get_relevant_documents(query)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.