mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 14:18:52 +00:00
community[patch]: add skipped test for inner product normalization (#14989)
--------- Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
f63906a9c2
commit
021b0484a8
@ -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)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="old relevance score feature")
|
||||
@pytest.mark.requires("faiss")
|
||||
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."""
|
||||
|
Loading…
Reference in New Issue
Block a user