Skip to content

The agent engineering platform.

community[patch]: add skipped test for inner product normalization (#14989)

Carey021b0484a8d9
diff --git a/libs/community/tests/unit_tests/vectorstores/test_faiss.py b/libs/community/tests/unit_tests/vectorstores/test_faiss.py
index 8b6cf76751..db8228962c 100644
--- a/libs/community/tests/unit_tests/vectorstores/test_faiss.py
+++ b/libs/community/tests/unit_tests/vectorstores/test_faiss.py
@@ -10,6 +10,7 @@ from langchain_core.documents import Document
from langchain_community.docstore.base import Docstore
from langchain_community.docstore.in_memory import InMemoryDocstore
from langchain_community.vectorstores.faiss import FAISS
+from langchain_community.vectorstores.utils import DistanceStrategy
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
_PAGE_CONTENT = """This is a page about LangChain.
@@ -687,6 +688,26 @@ def test_missing_normalize_score_fn() -> None:
faiss_instance.similarity_search_with_relevance_scores("foo", k=2)
[email protected](reason="old relevance score feature")
+def test_ip_score() -> None:
+ embedding = FakeEmbeddings()
+ vector = embedding.embed_query("hi")
+ assert vector == [1] * 9 + [0], f"FakeEmbeddings() has changed, produced {vector}"
+
+ db = FAISS.from_texts(
+ ["sundays coming so i drive my car"],
+ embedding=FakeEmbeddings(),
+ distance_strategy=DistanceStrategy.MAX_INNER_PRODUCT,
+ )
+ scores = db.similarity_search_with_relevance_scores("sundays", k=1)
+ assert len(scores) == 1, "only one vector should be in db"
+ _, score = scores[0]
+ assert (
+ score == 1
+ ), f"expected inner product of equivalent vectors to be 1, not {score}"
+
+
@pytest.mark.requires("faiss")
async def test_async_missing_normalize_score_fn() -> None:
"""Test doesn't perform similarity search without a valid distance strategy."""