Skip to content

Commit

Permalink
Merge branch 'main' into qdrant-hybrid-retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Apr 23, 2024
2 parents 7a98c2f + ffe0b74 commit 3fbf703
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 1,494 deletions.
5 changes: 0 additions & 5 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ integration:unstructured-fileconverter:
- any-glob-to-any-file: "integrations/unstructured/**/*"
- any-glob-to-any-file: ".github/workflows/unstructured.yml"

integration:uptrain:
- changed-files:
- any-glob-to-any-file: "integrations/uptrain/**/*"
- any-glob-to-any-file: ".github/workflows/uptrain.yml"

integration:weaviate:
- changed-files:
- any-glob-to-any-file: "integrations/weaviate/**/*"
Expand Down
76 changes: 0 additions & 76 deletions .github/workflows/uptrain.yml

This file was deleted.

60 changes: 30 additions & 30 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0

from .retriever import QdrantEmbeddingRetriever, QdrantHybridRetriever, QdrantSparseRetriever
from .retriever import QdrantEmbeddingRetriever, QdrantHybridRetriever, QdrantSparseEmbeddingRetriever

__all__ = ("QdrantEmbeddingRetriever", "QdrantSparseRetriever", "QdrantHybridRetriever")
__all__ = ("QdrantEmbeddingRetriever", "QdrantSparseEmbeddingRetriever", "QdrantHybridRetriever")
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def run(


@component
class QdrantSparseRetriever:
class QdrantSparseEmbeddingRetriever:
"""
A component for retrieving documents from an QdrantDocumentStore using sparse vectors.
Usage example:
```python
from haystack_integrations.components.retrievers.qdrant import QdrantSparseRetriever
from haystack_integrations.components.retrievers.qdrant import QdrantSparseEmbeddingRetriever
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
from haystack.dataclasses.sparse_embedding import SparseEmbedding
Expand All @@ -146,7 +146,7 @@ class QdrantSparseRetriever:
doc = Document(content="test", sparse_embedding=SparseEmbedding(indices=[0, 3, 5], values=[0.1, 0.5, 0.12]))
document_store.write_documents([doc])
retriever = QdrantSparseRetriever(document_store=document_store)
retriever = QdrantSparseEmbeddingRetriever(document_store=document_store)
sparse_embedding = SparseEmbedding(indices=[0, 1, 2, 3], values=[0.1, 0.8, 0.05, 0.33])
retriever.run(query_sparse_embedding=sparse_embedding)
```
Expand All @@ -161,7 +161,7 @@ def __init__(
return_embedding: bool = False,
):
"""
Create a QdrantSparseRetriever component.
Create a QdrantSparseEmbeddingRetriever component.
:param document_store: An instance of QdrantDocumentStore.
:param filters: A dictionary with filters to narrow down the search space. Default is None.
Expand Down Expand Up @@ -202,7 +202,7 @@ def to_dict(self) -> Dict[str, Any]:
return d

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "QdrantSparseRetriever":
def from_dict(cls, data: Dict[str, Any]) -> "QdrantSparseEmbeddingRetriever":
"""
Deserializes the component from a dictionary.
Expand Down
16 changes: 8 additions & 8 deletions integrations/qdrant/tests/test_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from haystack_integrations.components.retrievers.qdrant import (
QdrantEmbeddingRetriever,
QdrantHybridRetriever,
QdrantSparseRetriever,
QdrantSparseEmbeddingRetriever,
)
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore

Expand Down Expand Up @@ -138,21 +138,21 @@ def test_run_with_sparse_activated(self, filterable_docs: List[Document]):
assert document.embedding is None


class TestQdrantSparseRetriever(FilterableDocsFixtureMixin):
class TestQdrantSparseEmbeddingRetriever(FilterableDocsFixtureMixin):
def test_init_default(self):
document_store = QdrantDocumentStore(location=":memory:", index="test")
retriever = QdrantSparseRetriever(document_store=document_store)
retriever = QdrantSparseEmbeddingRetriever(document_store=document_store)
assert retriever._document_store == document_store
assert retriever._filters is None
assert retriever._top_k == 10
assert retriever._return_embedding is False

def test_to_dict(self):
document_store = QdrantDocumentStore(location=":memory:", index="test")
retriever = QdrantSparseRetriever(document_store=document_store)
retriever = QdrantSparseEmbeddingRetriever(document_store=document_store)
res = retriever.to_dict()
assert res == {
"type": "haystack_integrations.components.retrievers.qdrant.retriever.QdrantSparseRetriever",
"type": "haystack_integrations.components.retrievers.qdrant.retriever.QdrantSparseEmbeddingRetriever",
"init_parameters": {
"document_store": {
"type": "haystack_integrations.document_stores.qdrant.document_store.QdrantDocumentStore",
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_to_dict(self):

def test_from_dict(self):
data = {
"type": "haystack_integrations.components.retrievers.qdrant.retriever.QdrantSparseRetriever",
"type": "haystack_integrations.components.retrievers.qdrant.retriever.QdrantSparseEmbeddingRetriever",
"init_parameters": {
"document_store": {
"init_parameters": {"location": ":memory:", "index": "test"},
Expand All @@ -217,7 +217,7 @@ def test_from_dict(self):
"return_embedding": True,
},
}
retriever = QdrantSparseRetriever.from_dict(data)
retriever = QdrantSparseEmbeddingRetriever.from_dict(data)
assert isinstance(retriever._document_store, QdrantDocumentStore)
assert retriever._document_store.index == "test"
assert retriever._filters is None
Expand All @@ -233,7 +233,7 @@ def test_run(self, filterable_docs: List[Document]):
doc.sparse_embedding = SparseEmbedding.from_dict(_generate_mocked_sparse_embedding(1)[0])

document_store.write_documents(filterable_docs)
retriever = QdrantSparseRetriever(document_store=document_store)
retriever = QdrantSparseEmbeddingRetriever(document_store=document_store)
sparse_embedding = SparseEmbedding(indices=[0, 1, 2, 3], values=[0.1, 0.8, 0.05, 0.33])

results: List[Document] = retriever.run(query_sparse_embedding=sparse_embedding)["documents"]
Expand Down
3 changes: 2 additions & 1 deletion integrations/ragas/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = ["haystack-ai", "ragas==0.1.1"]
dependencies = ["haystack-ai", "ragas"]

[project.urls]
Source = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/ragas"
Expand Down Expand Up @@ -152,6 +152,7 @@ module = [
"haystack.*",
"pytest.*",
"ragas.*",
"datasets.*",
"numpy",
"grpc",
"haystack_integrations.*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json
from typing import Any, Callable, Dict, List, Optional, Union

from datasets import Dataset # type: ignore
from datasets import Dataset
from haystack import DeserializationError, component, default_from_dict, default_to_dict

from ragas import evaluate # type: ignore
from ragas.evaluation import Result # type: ignore
from ragas.metrics.base import Metric # type: ignore
from ragas.evaluation import Result
from ragas.metrics.base import Metric

from .metrics import (
METRIC_DESCRIPTORS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ContextUtilization, # type: ignore
Faithfulness, # type: ignore
)
from ragas.metrics.base import Metric # type: ignore
from ragas.metrics.base import Metric


class RagasBaseEnum(Enum):
Expand Down
73 changes: 0 additions & 73 deletions integrations/uptrain/LICENSE.txt

This file was deleted.

Loading

0 comments on commit 3fbf703

Please sign in to comment.