elasticsearch-haystack 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

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.

Potentially problematic release.


This version of elasticsearch-haystack might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: elasticsearch-haystack
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Haystack 2.x Document Store for ElasticSearch
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/elasticsearch#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
@@ -9,6 +9,7 @@ Author-email: Silvano Cerza <silvanocerza@gmail.com>
9
9
  License-Expression: Apache-2.0
10
10
  License-File: LICENSE
11
11
  Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: Apache Software License
12
13
  Classifier: Programming Language :: Python
13
14
  Classifier: Programming Language :: Python :: 3.8
14
15
  Classifier: Programming Language :: Python :: 3.9
@@ -2,9 +2,9 @@ haystack_integrations/components/retrievers/elasticsearch/__init__.py,sha256=cSJ
2
2
  haystack_integrations/components/retrievers/elasticsearch/bm25_retriever.py,sha256=fFx554MTcUHnQZa2SgC0PzIR85YVbqAdMNOiXKkVSu8,4849
3
3
  haystack_integrations/components/retrievers/elasticsearch/embedding_retriever.py,sha256=RcIbSMELiKIJsD-8F_u76J33YRt5bLr6lHnoX-hVQ1M,4990
4
4
  haystack_integrations/document_stores/elasticsearch/__init__.py,sha256=YTfu94dtVUBogbJFr1aJrKuaI6-Bw9VuHfPoyU7M8os,207
5
- haystack_integrations/document_stores/elasticsearch/document_store.py,sha256=m_NvCRt0xQhVuTdkfxaqql4sB7qVDyYc8f9LaWMoLyA,17688
5
+ haystack_integrations/document_stores/elasticsearch/document_store.py,sha256=XMbrn-dsRw0HS8mPMreGCO3cRQnwwU_UA3OzWb3pi_4,18304
6
6
  haystack_integrations/document_stores/elasticsearch/filters.py,sha256=L1tN7YCIDuNdhGrBQdPoqXFk37x__2-K038xZ6PRdNQ,9923
7
- elasticsearch_haystack-0.4.0.dist-info/METADATA,sha256=sHF3d2RaJjZ8DQ8W7Vm1e8iZN01W8BjlsPIUkrpF8yg,2105
8
- elasticsearch_haystack-0.4.0.dist-info/WHEEL,sha256=uNdcs2TADwSd5pVaP0Z_kcjcvvTUklh2S7bxZMF8Uj0,87
9
- elasticsearch_haystack-0.4.0.dist-info/licenses/LICENSE,sha256=_M2kulivnaiTHiW-5CRlZrPmH47tt04pBgAgeDvfYi4,11342
10
- elasticsearch_haystack-0.4.0.dist-info/RECORD,,
7
+ elasticsearch_haystack-0.5.0.dist-info/METADATA,sha256=bKt2Am26Ey5iq0ZQw7JOeBSu_Em7-e9iDdl1eHqCt08,2168
8
+ elasticsearch_haystack-0.5.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
9
+ elasticsearch_haystack-0.5.0.dist-info/licenses/LICENSE,sha256=_M2kulivnaiTHiW-5CRlZrPmH47tt04pBgAgeDvfYi4,11342
10
+ elasticsearch_haystack-0.5.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.22.4
2
+ Generator: hatchling 1.24.2
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -63,6 +63,7 @@ class ElasticsearchDocumentStore:
63
63
  self,
64
64
  *,
65
65
  hosts: Optional[Hosts] = None,
66
+ custom_mapping: Optional[Dict[str, Any]] = None,
66
67
  index: str = "default",
67
68
  embedding_similarity_function: Literal["cosine", "dot_product", "l2_norm", "max_inner_product"] = "cosine",
68
69
  **kwargs,
@@ -82,6 +83,7 @@ class ElasticsearchDocumentStore:
82
83
  [reference](https://elasticsearch-py.readthedocs.io/en/stable/api.html#module-elasticsearch)
83
84
 
84
85
  :param hosts: List of hosts running the Elasticsearch client.
86
+ :param custom_mapping: Custom mapping for the index. If not provided, a default mapping will be used.
85
87
  :param index: Name of index in Elasticsearch.
86
88
  :param embedding_similarity_function: The similarity function used to compare Documents embeddings.
87
89
  This parameter only takes effect if the index does not yet exist and is created.
@@ -98,29 +100,37 @@ class ElasticsearchDocumentStore:
98
100
  )
99
101
  self._index = index
100
102
  self._embedding_similarity_function = embedding_similarity_function
103
+ self._custom_mapping = custom_mapping
101
104
  self._kwargs = kwargs
102
105
 
103
106
  # Check client connection, this will raise if not connected
104
107
  self._client.info()
105
108
 
106
- # configure mapping for the embedding field
107
- mappings = {
108
- "properties": {
109
- "embedding": {"type": "dense_vector", "index": True, "similarity": embedding_similarity_function},
110
- "content": {"type": "text"},
111
- },
112
- "dynamic_templates": [
113
- {
114
- "strings": {
115
- "path_match": "*",
116
- "match_mapping_type": "string",
117
- "mapping": {
118
- "type": "keyword",
119
- },
109
+ if self._custom_mapping and not isinstance(self._custom_mapping, Dict):
110
+ msg = "custom_mapping must be a dictionary"
111
+ raise ValueError(msg)
112
+
113
+ if self._custom_mapping:
114
+ mappings = self._custom_mapping
115
+ else:
116
+ # Configure mapping for the embedding field if none is provided
117
+ mappings = {
118
+ "properties": {
119
+ "embedding": {"type": "dense_vector", "index": True, "similarity": embedding_similarity_function},
120
+ "content": {"type": "text"},
121
+ },
122
+ "dynamic_templates": [
123
+ {
124
+ "strings": {
125
+ "path_match": "*",
126
+ "match_mapping_type": "string",
127
+ "mapping": {
128
+ "type": "keyword",
129
+ },
130
+ }
120
131
  }
121
- }
122
- ],
123
- }
132
+ ],
133
+ }
124
134
 
125
135
  # Create the index if it doesn't exist
126
136
  if not self._client.indices.exists(index=index):
@@ -139,6 +149,7 @@ class ElasticsearchDocumentStore:
139
149
  return default_to_dict(
140
150
  self,
141
151
  hosts=self._hosts,
152
+ custom_mapping=self._custom_mapping,
142
153
  index=self._index,
143
154
  embedding_similarity_function=self._embedding_similarity_function,
144
155
  **self._kwargs,