# ElasticSearch Langchain retreive embedding based on particular threshold

**URL:** <https://discuss.elastic.co/t/elasticsearch-langchain-retreive-embedding-based-on-particular-threshold/354794>\
**Category:** Elasticsearch\
**Created:** [March 6, 2024, 5:24am UTC](https://discuss.elastic.co/t/elasticsearch-langchain-retreive-embedding-based-on-particular-threshold/354794 "2024-03-06T05:24:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanzeel\_Abbas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanzeel_abbas/32/132385_2.png) [@Tanzeel\_Abbas](https://discuss.elastic.co/u/Tanzeel_Abbas)\
**Post date:** [March 6, 2024, 5:24am UTC](https://discuss.elastic.co/t/elasticsearch-langchain-retreive-embedding-based-on-particular-threshold/354794/1 "2024-03-06T05:24:47Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![iulia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iulia/32/124658_2.png) [@iulia](https://discuss.elastic.co/u/iulia)\
**Post date:** [March 6, 2024, 1:38pm UTC](https://discuss.elastic.co/t/elasticsearch-langchain-retreive-embedding-based-on-particular-threshold/354794/2 "2024-03-06T13:38:11Z")

</div>

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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 3, 2024, 1:38pm UTC](https://discuss.elastic.co/t/elasticsearch-langchain-retreive-embedding-based-on-particular-threshold/354794/3 "2024-04-03T13:38:38Z")

</div>

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