-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e941823
commit bdfcf56
Showing
5 changed files
with
176 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pytest | |
pytest-xdist[psutil] | ||
pytest-asyncio | ||
llama_index | ||
pytest-asyncio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from ragas.embeddings.base import InfinityEmbeddings | ||
|
||
try: | ||
import infinity_emb # noqa | ||
import torch # noqa | ||
|
||
INFINITY_AVAILABLE = True | ||
except ImportError: | ||
INFINITY_AVAILABLE = False | ||
|
||
|
||
@pytest.mark.skipif(not INFINITY_AVAILABLE, reason="infinity_emb is not installed.") | ||
@pytest.mark.asyncio | ||
async def test_basic_embedding(): | ||
embedding_engine = InfinityEmbeddings(model_name="BAAI/bge-small-en-v1.5") | ||
async with embedding_engine: | ||
embeddings = await embedding_engine.aembed_documents( | ||
[ | ||
"Paris is in France", | ||
"The capital of France is Paris", | ||
"Infintiy batches embeddings on the fly", | ||
] | ||
* 20 | ||
) | ||
assert isinstance(embeddings, list) | ||
array = np.array(embeddings) | ||
assert array.shape == (60, 384) | ||
assert array[0] @ array[1] > array[0] @ array[2] | ||
|
||
|
||
@pytest.mark.skipif(not INFINITY_AVAILABLE, reason="infinity_emb is not installed.") | ||
@pytest.mark.asyncio | ||
async def test_rerank(): | ||
rerank_engine = InfinityEmbeddings(model_name="BAAI/bge-reranker-base") | ||
|
||
async with rerank_engine: | ||
rankings = await rerank_engine.arerank( | ||
"Where is Paris?", | ||
[ | ||
"Paris is in France", | ||
"I don't know the capital of Paris.", | ||
"Dummy sentence", | ||
], | ||
) | ||
assert len(rankings) == 3 | ||
assert rankings[0] > rankings[1] | ||
assert rankings[0] > rankings[2] |