milvus-haystack 0.0.7__tar.gz → 0.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/PKG-INFO +1 -1
  2. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/src/milvus_haystack/__about__.py +1 -1
  3. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/src/milvus_haystack/milvus_embedding_retriever.py +30 -1
  4. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/tests/test_document_store.py +8 -9
  5. milvus_haystack-0.0.8/tests/test_embedding_retriever.py +117 -0
  6. milvus_haystack-0.0.7/tests/test_embedding_retriever.py +0 -46
  7. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/.github/mergify.yml +0 -0
  8. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/.github/workflows/main.yml +0 -0
  9. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/.github/workflows/test.yml +0 -0
  10. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/.gitignore +0 -0
  11. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/LICENSE.txt +0 -0
  12. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/OWNERS +0 -0
  13. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/README.md +0 -0
  14. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/pyproject.toml +0 -0
  15. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/src/milvus_haystack/__init__.py +0 -0
  16. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/src/milvus_haystack/document_store.py +0 -0
  17. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/src/milvus_haystack/filters.py +0 -0
  18. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/tests/__init__.py +0 -0
  19. {milvus_haystack-0.0.7 → milvus_haystack-0.0.8}/tests/test_filters.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: milvus-haystack
3
- Version: 0.0.7
3
+ Version: 0.0.8
4
4
  Project-URL: Documentation, https://github.com/milvus-io/milvus-haystack#readme
5
5
  Project-URL: Issues, https://github.com/milvus-io/milvus-haystack/issues
6
6
  Project-URL: Source, https://github.com/milvus-io/milvus-haystack
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2023-present Tuana Celik <tuana.celik@deepset.ai>
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
- __version__ = "0.0.7"
4
+ __version__ = "0.0.8"
@@ -1,6 +1,6 @@
1
1
  from typing import Any, Dict, List, Optional
2
2
 
3
- from haystack import Document, component
3
+ from haystack import DeserializationError, Document, component, default_from_dict, default_to_dict
4
4
 
5
5
  from milvus_haystack import MilvusDocumentStore
6
6
 
@@ -23,6 +23,35 @@ class MilvusEmbeddingRetriever:
23
23
  self.top_k = top_k
24
24
  self.document_store = document_store
25
25
 
26
+ def to_dict(self) -> Dict[str, Any]:
27
+ """
28
+ Returns a dictionary representation of the retriever component.
29
+
30
+ :returns:
31
+ A dictionary representation of the retriever component.
32
+ """
33
+ return default_to_dict(
34
+ self, document_store=self.document_store.to_dict(), filters=self.filters, top_k=self.top_k
35
+ )
36
+
37
+ @classmethod
38
+ def from_dict(cls, data: Dict[str, Any]) -> "MilvusEmbeddingRetriever":
39
+ """
40
+ Creates a new retriever from a dictionary.
41
+
42
+ :param data: The dictionary to use to create the retriever.
43
+ :return: A new retriever.
44
+ """
45
+ init_params = data.get("init_parameters", {})
46
+ if "document_store" not in init_params:
47
+ err_msg = "Missing 'document_store' in serialization data"
48
+ raise DeserializationError(err_msg)
49
+
50
+ docstore = MilvusDocumentStore.from_dict(init_params["document_store"])
51
+ data["init_parameters"]["document_store"] = docstore
52
+
53
+ return default_from_dict(cls, data)
54
+
26
55
  @component.output_types(documents=List[Document])
27
56
  def run(self, query_embedding: List[float]) -> Dict[str, List[Document]]:
28
57
  """
@@ -10,18 +10,17 @@ from src.milvus_haystack import MilvusDocumentStore
10
10
 
11
11
  logger = logging.getLogger(__name__)
12
12
 
13
+ DEFAULT_CONNECTION_ARGS = {
14
+ "uri": "http://localhost:19530",
15
+ # "uri": "./milvus_test.db", # This uri works for Milvus Lite
16
+ }
17
+
13
18
 
14
19
  class TestDocumentStore(CountDocumentsTest, WriteDocumentsTest, DeleteDocumentsTest):
15
20
  @pytest.fixture
16
21
  def document_store(self) -> MilvusDocumentStore:
17
22
  return MilvusDocumentStore(
18
- connection_args={
19
- "host": "localhost",
20
- "port": "19530",
21
- "user": "",
22
- "password": "",
23
- "secure": False,
24
- },
23
+ connection_args=DEFAULT_CONNECTION_ARGS,
25
24
  drop_old=True,
26
25
  )
27
26
 
@@ -61,7 +60,7 @@ class TestDocumentStore(CountDocumentsTest, WriteDocumentsTest, DeleteDocumentsT
61
60
  "collection_name": "HaystackCollection",
62
61
  "collection_description": "",
63
62
  "collection_properties": None,
64
- "connection_args": {"host": "localhost", "port": "19530", "user": "", "password": "", "secure": False},
63
+ "connection_args": DEFAULT_CONNECTION_ARGS,
65
64
  "consistency_level": "Session",
66
65
  "index_params": None,
67
66
  "search_params": None,
@@ -78,6 +77,6 @@ class TestDocumentStore(CountDocumentsTest, WriteDocumentsTest, DeleteDocumentsT
78
77
  assert document_store_dict == expected_dict
79
78
  reconstructed_document_store = MilvusDocumentStore.from_dict(document_store_dict)
80
79
  for field in vars(reconstructed_document_store):
81
- if field.startswith("__"):
80
+ if field.startswith("__") or field == "alias":
82
81
  continue
83
82
  assert getattr(reconstructed_document_store, field) == getattr(document_store, field)
@@ -0,0 +1,117 @@
1
+ import logging
2
+
3
+ import pytest
4
+ from haystack import Document
5
+
6
+ from src.milvus_haystack import MilvusDocumentStore
7
+ from src.milvus_haystack.milvus_embedding_retriever import MilvusEmbeddingRetriever
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+ DEFAULT_CONNECTION_ARGS = {
12
+ "uri": "http://localhost:19530",
13
+ # "uri": "./milvus_test.db", # This uri works for Milvus Lite
14
+ }
15
+
16
+
17
+ class TestMilvusEmbeddingTests:
18
+ @pytest.fixture
19
+ def document_store(self) -> MilvusDocumentStore:
20
+ return MilvusDocumentStore(
21
+ connection_args=DEFAULT_CONNECTION_ARGS,
22
+ drop_old=True,
23
+ )
24
+
25
+ def test_run(self, document_store: MilvusDocumentStore):
26
+ documents = []
27
+ doc = Document(
28
+ content="A Foo Document",
29
+ meta={
30
+ "name": "name_0",
31
+ "page": "100",
32
+ "chapter": "intro",
33
+ "number": 2,
34
+ "date": "1969-07-21T20:17:40",
35
+ },
36
+ embedding=[-10.0] * 128,
37
+ )
38
+ documents.append(doc)
39
+ document_store.write_documents(documents)
40
+ retriever = MilvusEmbeddingRetriever(
41
+ document_store,
42
+ )
43
+ query_embedding = [-10.0] * 128
44
+ res = retriever.run(query_embedding)
45
+ assert res["documents"] == documents
46
+
47
+ def test_to_dict(self, document_store: MilvusDocumentStore):
48
+ expected_dict = {
49
+ "type": "src.milvus_haystack.document_store.MilvusDocumentStore",
50
+ "init_parameters": {
51
+ "collection_name": "HaystackCollection",
52
+ "collection_description": "",
53
+ "collection_properties": None,
54
+ "connection_args": DEFAULT_CONNECTION_ARGS,
55
+ "consistency_level": "Session",
56
+ "index_params": None,
57
+ "search_params": None,
58
+ "drop_old": True,
59
+ "primary_field": "id",
60
+ "text_field": "text",
61
+ "vector_field": "vector",
62
+ "partition_key_field": None,
63
+ "partition_names": None,
64
+ "replica_number": 1,
65
+ "timeout": None,
66
+ },
67
+ }
68
+ retriever = MilvusEmbeddingRetriever(document_store)
69
+ result = retriever.to_dict()
70
+
71
+ assert result["type"] == "src.milvus_haystack.milvus_embedding_retriever.MilvusEmbeddingRetriever"
72
+ assert result["init_parameters"]["document_store"] == expected_dict
73
+
74
+ def test_from_dict(self, document_store: MilvusDocumentStore):
75
+ retriever_dict = {
76
+ "type": "src.milvus_haystack.milvus_embedding_retriever.MilvusEmbeddingRetriever",
77
+ "init_parameters": {
78
+ "document_store": {
79
+ "type": "milvus_haystack.document_store.MilvusDocumentStore",
80
+ "init_parameters": {
81
+ "collection_name": "HaystackCollection",
82
+ "collection_description": "",
83
+ "collection_properties": None,
84
+ "connection_args": DEFAULT_CONNECTION_ARGS,
85
+ "consistency_level": "Session",
86
+ "index_params": None,
87
+ "search_params": None,
88
+ "drop_old": True,
89
+ "primary_field": "id",
90
+ "text_field": "text",
91
+ "vector_field": "vector",
92
+ "partition_key_field": None,
93
+ "partition_names": None,
94
+ "replica_number": 1,
95
+ "timeout": None,
96
+ },
97
+ },
98
+ "filters": None,
99
+ "top_k": 10,
100
+ },
101
+ }
102
+
103
+ retriever = MilvusEmbeddingRetriever(document_store)
104
+
105
+ reconstructed_retriever = MilvusEmbeddingRetriever.from_dict(retriever_dict)
106
+ for field in vars(reconstructed_retriever):
107
+ if field.startswith("__"):
108
+ continue
109
+ elif field == "document_store":
110
+ for doc_store_field in vars(document_store):
111
+ if doc_store_field.startswith("__") or doc_store_field == "alias":
112
+ continue
113
+ assert getattr(reconstructed_retriever.document_store, doc_store_field) == getattr(
114
+ document_store, doc_store_field
115
+ )
116
+ else:
117
+ assert getattr(reconstructed_retriever, field) == getattr(retriever, field)
@@ -1,46 +0,0 @@
1
- import logging
2
-
3
- import pytest
4
- from haystack import Document
5
-
6
- from src.milvus_haystack import MilvusDocumentStore
7
- from src.milvus_haystack.milvus_embedding_retriever import MilvusEmbeddingRetriever
8
-
9
- logger = logging.getLogger(__name__)
10
-
11
-
12
- class TestMilvusEmbeddingTests:
13
- @pytest.fixture
14
- def document_store(self) -> MilvusDocumentStore:
15
- return MilvusDocumentStore(
16
- connection_args={
17
- "host": "localhost",
18
- "port": "19530",
19
- "user": "",
20
- "password": "",
21
- "secure": False,
22
- },
23
- drop_old=True,
24
- )
25
-
26
- def test_run(self, document_store: MilvusDocumentStore):
27
- documents = []
28
- doc = Document(
29
- content="A Foo Document",
30
- meta={
31
- "name": "name_0",
32
- "page": "100",
33
- "chapter": "intro",
34
- "number": 2,
35
- "date": "1969-07-21T20:17:40",
36
- },
37
- embedding=[-10.0] * 128,
38
- )
39
- documents.append(doc)
40
- document_store.write_documents(documents)
41
- retriever = MilvusEmbeddingRetriever(
42
- document_store,
43
- )
44
- query_embedding = [-10.0] * 128
45
- res = retriever.run(query_embedding)
46
- assert res["documents"] == documents
File without changes