mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-05 20:58:25 +00:00
Add/faiss test score threshold (#8224)
# What - This is to add test for faiss vector store with score threshold <!-- Thank you for contributing to LangChain! Replace this comment with: - Description: This is to add test for faiss vector store with score threshold - Issue: None - Dependencies: None - Tag maintainer: @rlancemartin, @eyurtsev - Twitter handle: @MlopsJ Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally. If you're adding a new integration, please include: 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. Maintainer responsibilities: - General / Misc / if you don't know who to tag: @baskaryan - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev - Models / Prompts: @hwchase17, @baskaryan - Memory: @hwchase17 - Agents / Tools / Toolkits: @hinthornw - Tracing / Callbacks: @agola11 - Async: @agola11 If no one reviews your PR within a few days, feel free to @-mention the same people again. See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md -->
This commit is contained in:
parent
bed8eb978e
commit
af788b7cf0
@ -289,6 +289,23 @@ def test_faiss_similarity_search_with_relevance_scores() -> None:
|
|||||||
assert score == 1.0
|
assert score == 1.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_faiss_similarity_search_with_relevance_scores_with_threshold() -> None:
|
||||||
|
"""Test the similarity search with normalized similarities with score threshold."""
|
||||||
|
texts = ["foo", "bar", "baz"]
|
||||||
|
docsearch = FAISS.from_texts(
|
||||||
|
texts,
|
||||||
|
FakeEmbeddings(),
|
||||||
|
relevance_score_fn=lambda score: 1.0 - score / math.sqrt(2),
|
||||||
|
)
|
||||||
|
outputs = docsearch.similarity_search_with_relevance_scores(
|
||||||
|
"foo", k=2, score_threshold=0.5
|
||||||
|
)
|
||||||
|
assert len(outputs) == 1
|
||||||
|
output, score = outputs[0]
|
||||||
|
assert output == Document(page_content="foo")
|
||||||
|
assert score == 1.0
|
||||||
|
|
||||||
|
|
||||||
def test_faiss_invalid_normalize_fn() -> None:
|
def test_faiss_invalid_normalize_fn() -> None:
|
||||||
"""Test the similarity search with normalized similarities."""
|
"""Test the similarity search with normalized similarities."""
|
||||||
texts = ["foo", "bar", "baz"]
|
texts = ["foo", "bar", "baz"]
|
||||||
|
Loading…
Reference in New Issue
Block a user