upstash-haystack 0.1.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.
- haystack_integrations/components/retrievers/upstash/__init__.py +8 -0
- haystack_integrations/components/retrievers/upstash/embedding_retriever.py +108 -0
- haystack_integrations/components/retrievers/upstash/hybrid_retriever.py +116 -0
- haystack_integrations/document_stores/upstash/__init__.py +7 -0
- haystack_integrations/document_stores/upstash/document_store.py +191 -0
- haystack_integrations/document_stores/upstash/filters.py +130 -0
- haystack_integrations/py.typed +0 -0
- upstash_haystack-0.1.0.dist-info/METADATA +175 -0
- upstash_haystack-0.1.0.dist-info/RECORD +11 -0
- upstash_haystack-0.1.0.dist-info/WHEEL +4 -0
- upstash_haystack-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Avish Sinha <avishsinha10@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from .embedding_retriever import UpstashEmbeddingRetriever
|
|
6
|
+
from .hybrid_retriever import UpstashHybridRetriever
|
|
7
|
+
|
|
8
|
+
__all__ = ["UpstashEmbeddingRetriever", "UpstashHybridRetriever"]
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Avish Sinha <avishsinha10@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from haystack import component, default_from_dict, default_to_dict
|
|
8
|
+
from haystack.dataclasses import Document
|
|
9
|
+
|
|
10
|
+
from haystack_integrations.document_stores.upstash import UpstashDocumentStore
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@component
|
|
14
|
+
class UpstashEmbeddingRetriever:
|
|
15
|
+
"""
|
|
16
|
+
A component for retrieving documents from an UpstashDocumentStore using dense embeddings.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
document_store: UpstashDocumentStore,
|
|
22
|
+
filters: dict[str, Any] | None = None,
|
|
23
|
+
top_k: int = 10,
|
|
24
|
+
) -> None:
|
|
25
|
+
"""
|
|
26
|
+
Initializes the UpstashEmbeddingRetriever.
|
|
27
|
+
|
|
28
|
+
:param document_store: The UpstashDocumentStore instance to retrieve documents from.
|
|
29
|
+
:param filters: Optional filters to narrow down the search space.
|
|
30
|
+
:param top_k: The maximum number of documents to retrieve.
|
|
31
|
+
"""
|
|
32
|
+
self.document_store = document_store
|
|
33
|
+
self.filters = filters
|
|
34
|
+
self.top_k = top_k
|
|
35
|
+
|
|
36
|
+
def to_dict(self) -> dict[str, Any]:
|
|
37
|
+
"""
|
|
38
|
+
Serializes this Retriever to a dictionary.
|
|
39
|
+
|
|
40
|
+
:returns: The serialized Retriever.
|
|
41
|
+
"""
|
|
42
|
+
return default_to_dict(
|
|
43
|
+
self,
|
|
44
|
+
document_store=self.document_store.to_dict(),
|
|
45
|
+
filters=self.filters,
|
|
46
|
+
top_k=self.top_k,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def from_dict(cls, data: dict[str, Any]) -> "UpstashEmbeddingRetriever":
|
|
51
|
+
"""
|
|
52
|
+
Deserializes a dictionary into a Retriever.
|
|
53
|
+
|
|
54
|
+
:param data: The serialized Retriever.
|
|
55
|
+
:returns: The deserialized Retriever.
|
|
56
|
+
"""
|
|
57
|
+
data["init_parameters"]["document_store"] = UpstashDocumentStore.from_dict(
|
|
58
|
+
data["init_parameters"]["document_store"]
|
|
59
|
+
)
|
|
60
|
+
return default_from_dict(cls, data)
|
|
61
|
+
|
|
62
|
+
@component.output_types(documents=list[Document])
|
|
63
|
+
def run(
|
|
64
|
+
self,
|
|
65
|
+
query_embedding: list[float],
|
|
66
|
+
filters: dict[str, Any] | None = None,
|
|
67
|
+
top_k: int | None = None,
|
|
68
|
+
) -> dict[str, Any]:
|
|
69
|
+
"""
|
|
70
|
+
Retrieves documents matching the given query embedding.
|
|
71
|
+
|
|
72
|
+
:param query_embedding: The dense embedding to query for.
|
|
73
|
+
:param filters: Optional filters to narrow down the search space.
|
|
74
|
+
:param top_k: The maximum number of documents to retrieve.
|
|
75
|
+
:returns: A dictionary with the following keys:
|
|
76
|
+
- `documents`: List of documents matching the query.
|
|
77
|
+
"""
|
|
78
|
+
filters = filters or self.filters
|
|
79
|
+
top_k = top_k or self.top_k
|
|
80
|
+
|
|
81
|
+
from haystack_integrations.document_stores.upstash.filters import _normalize_filters # noqa: PLC0415
|
|
82
|
+
|
|
83
|
+
filter_str = ""
|
|
84
|
+
if filters:
|
|
85
|
+
filter_str = _normalize_filters(filters)
|
|
86
|
+
|
|
87
|
+
results = self.document_store._index.query(
|
|
88
|
+
vector=query_embedding,
|
|
89
|
+
top_k=top_k,
|
|
90
|
+
filter=filter_str,
|
|
91
|
+
include_metadata=True,
|
|
92
|
+
include_vectors=True,
|
|
93
|
+
include_data=True,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
documents = []
|
|
97
|
+
for res in results:
|
|
98
|
+
documents.append(
|
|
99
|
+
Document(
|
|
100
|
+
id=res.id,
|
|
101
|
+
content=res.data,
|
|
102
|
+
embedding=res.vector,
|
|
103
|
+
meta=res.metadata or {},
|
|
104
|
+
score=res.score,
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return {"documents": documents}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Avish Sinha <avishsinha10@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from haystack import component, default_from_dict, default_to_dict
|
|
8
|
+
from haystack.dataclasses import Document, SparseEmbedding
|
|
9
|
+
|
|
10
|
+
from haystack_integrations.document_stores.upstash import UpstashDocumentStore
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@component
|
|
14
|
+
class UpstashHybridRetriever:
|
|
15
|
+
"""
|
|
16
|
+
A component for retrieving documents from an UpstashDocumentStore.
|
|
17
|
+
|
|
18
|
+
Uses both dense and sparse embeddings, combined via Upstash Vector's native Reciprocal Rank Fusion.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
document_store: UpstashDocumentStore,
|
|
24
|
+
filters: dict[str, Any] | None = None,
|
|
25
|
+
top_k: int = 10,
|
|
26
|
+
) -> None:
|
|
27
|
+
"""
|
|
28
|
+
Initializes the UpstashHybridRetriever.
|
|
29
|
+
|
|
30
|
+
:param document_store: The UpstashDocumentStore instance to retrieve documents from.
|
|
31
|
+
:param filters: Optional filters to narrow down the search space.
|
|
32
|
+
:param top_k: The maximum number of documents to retrieve.
|
|
33
|
+
"""
|
|
34
|
+
self.document_store = document_store
|
|
35
|
+
self.filters = filters
|
|
36
|
+
self.top_k = top_k
|
|
37
|
+
|
|
38
|
+
def to_dict(self) -> dict[str, Any]:
|
|
39
|
+
"""
|
|
40
|
+
Serializes this Retriever to a dictionary.
|
|
41
|
+
|
|
42
|
+
:returns: The serialized Retriever.
|
|
43
|
+
"""
|
|
44
|
+
return default_to_dict(
|
|
45
|
+
self,
|
|
46
|
+
document_store=self.document_store.to_dict(),
|
|
47
|
+
filters=self.filters,
|
|
48
|
+
top_k=self.top_k,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def from_dict(cls, data: dict[str, Any]) -> "UpstashHybridRetriever":
|
|
53
|
+
"""
|
|
54
|
+
Deserializes a dictionary into a Retriever.
|
|
55
|
+
|
|
56
|
+
:param data: The serialized Retriever.
|
|
57
|
+
:returns: The deserialized Retriever.
|
|
58
|
+
"""
|
|
59
|
+
data["init_parameters"]["document_store"] = UpstashDocumentStore.from_dict(
|
|
60
|
+
data["init_parameters"]["document_store"]
|
|
61
|
+
)
|
|
62
|
+
return default_from_dict(cls, data)
|
|
63
|
+
|
|
64
|
+
@component.output_types(documents=list[Document])
|
|
65
|
+
def run(
|
|
66
|
+
self,
|
|
67
|
+
query_embedding: list[float],
|
|
68
|
+
query_sparse_embedding: SparseEmbedding,
|
|
69
|
+
filters: dict[str, Any] | None = None,
|
|
70
|
+
top_k: int | None = None,
|
|
71
|
+
) -> dict[str, Any]:
|
|
72
|
+
"""
|
|
73
|
+
Retrieves documents matching the given dense and sparse query embeddings.
|
|
74
|
+
|
|
75
|
+
:param query_embedding: The dense embedding to query for.
|
|
76
|
+
:param query_sparse_embedding: The sparse embedding to query for.
|
|
77
|
+
:param filters: Optional filters to narrow down the search space.
|
|
78
|
+
:param top_k: The maximum number of documents to retrieve.
|
|
79
|
+
:returns: A dictionary with the following keys:
|
|
80
|
+
- `documents`: List of documents matching the query.
|
|
81
|
+
"""
|
|
82
|
+
filters = filters or self.filters
|
|
83
|
+
top_k = top_k or self.top_k
|
|
84
|
+
|
|
85
|
+
from haystack_integrations.document_stores.upstash.filters import _normalize_filters # noqa: PLC0415
|
|
86
|
+
|
|
87
|
+
filter_str = ""
|
|
88
|
+
if filters:
|
|
89
|
+
filter_str = _normalize_filters(filters)
|
|
90
|
+
|
|
91
|
+
# Parse query_sparse_embedding
|
|
92
|
+
sparse_vec = (list(query_sparse_embedding.indices), list(query_sparse_embedding.values))
|
|
93
|
+
|
|
94
|
+
results = self.document_store._index.query(
|
|
95
|
+
vector=query_embedding,
|
|
96
|
+
sparse_vector=sparse_vec,
|
|
97
|
+
top_k=top_k,
|
|
98
|
+
filter=filter_str,
|
|
99
|
+
include_metadata=True,
|
|
100
|
+
include_vectors=True,
|
|
101
|
+
include_data=True,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
documents = []
|
|
105
|
+
for res in results:
|
|
106
|
+
documents.append(
|
|
107
|
+
Document(
|
|
108
|
+
id=res.id,
|
|
109
|
+
content=res.data,
|
|
110
|
+
embedding=res.vector,
|
|
111
|
+
meta=res.metadata or {},
|
|
112
|
+
score=res.score,
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return {"documents": documents}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Avish Sinha <avishsinha10@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from haystack import default_from_dict, default_to_dict
|
|
9
|
+
from haystack.dataclasses import Document
|
|
10
|
+
from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError
|
|
11
|
+
from haystack.document_stores.types import DuplicatePolicy
|
|
12
|
+
from haystack.utils.auth import Secret, deserialize_secrets_inplace
|
|
13
|
+
from upstash_vector import Index
|
|
14
|
+
|
|
15
|
+
from .filters import _normalize_filters
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
TOP_K_LIMIT = 1000
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class UpstashDocumentStore:
|
|
23
|
+
"""
|
|
24
|
+
A Document Store using Upstash Vector as the backend.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
url: Secret = Secret.from_env_var("UPSTASH_VECTOR_REST_URL"),
|
|
30
|
+
token: Secret = Secret.from_env_var("UPSTASH_VECTOR_REST_TOKEN"),
|
|
31
|
+
) -> None:
|
|
32
|
+
"""
|
|
33
|
+
Initializes the UpstashDocumentStore.
|
|
34
|
+
|
|
35
|
+
:param url: The URL of the Upstash Vector index.
|
|
36
|
+
:param token: The REST token for the Upstash Vector index.
|
|
37
|
+
"""
|
|
38
|
+
self.url = url
|
|
39
|
+
self.token = token
|
|
40
|
+
url_val = url.resolve_value()
|
|
41
|
+
token_val = token.resolve_value()
|
|
42
|
+
if not isinstance(url_val, str) or not isinstance(token_val, str):
|
|
43
|
+
msg = "Upstash Vector URL and Token must be valid strings."
|
|
44
|
+
raise ValueError(msg)
|
|
45
|
+
self._index = Index(url=url_val, token=token_val)
|
|
46
|
+
|
|
47
|
+
def to_dict(self) -> dict[str, Any]:
|
|
48
|
+
"""
|
|
49
|
+
Serializes this Document Store to a dictionary.
|
|
50
|
+
|
|
51
|
+
:returns: The serialized Document Store.
|
|
52
|
+
"""
|
|
53
|
+
return default_to_dict(
|
|
54
|
+
self,
|
|
55
|
+
url=self.url.to_dict(),
|
|
56
|
+
token=self.token.to_dict(),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def from_dict(cls, data: dict[str, Any]) -> "UpstashDocumentStore":
|
|
61
|
+
"""
|
|
62
|
+
Deserializes a dictionary into a Document Store.
|
|
63
|
+
|
|
64
|
+
:param data: The serialized Document Store.
|
|
65
|
+
:returns: The deserialized Document Store.
|
|
66
|
+
"""
|
|
67
|
+
deserialize_secrets_inplace(data["init_parameters"], keys=["url", "token"])
|
|
68
|
+
return default_from_dict(cls, data)
|
|
69
|
+
|
|
70
|
+
def count_documents(self) -> int:
|
|
71
|
+
"""
|
|
72
|
+
Returns the number of documents in the Document Store.
|
|
73
|
+
|
|
74
|
+
:returns: The total number of documents in the Upstash Vector index.
|
|
75
|
+
"""
|
|
76
|
+
return self._index.info().vector_count
|
|
77
|
+
|
|
78
|
+
def write_documents(
|
|
79
|
+
self,
|
|
80
|
+
documents: list[Document],
|
|
81
|
+
policy: DuplicatePolicy = DuplicatePolicy.NONE,
|
|
82
|
+
) -> int:
|
|
83
|
+
"""
|
|
84
|
+
Writes documents to the Upstash Vector index.
|
|
85
|
+
|
|
86
|
+
:param documents: A list of Documents to be written to the Document Store.
|
|
87
|
+
:param policy: The duplicate policy to apply when a document with the same ID already exists.
|
|
88
|
+
If `DuplicatePolicy.NONE`, it defaults to `DuplicatePolicy.OVERWRITE`.
|
|
89
|
+
`DuplicatePolicy.FAIL` will raise a `DuplicateDocumentError`.
|
|
90
|
+
`DuplicatePolicy.SKIP` will skip existing documents.
|
|
91
|
+
`DuplicatePolicy.OVERWRITE` will replace existing documents.
|
|
92
|
+
:returns: The number of documents written.
|
|
93
|
+
:raises DuplicateDocumentError: If a document with the same ID already exists and `policy` is `FAIL`.
|
|
94
|
+
:raises DocumentStoreError: If a document does not have an embedding.
|
|
95
|
+
"""
|
|
96
|
+
if len(documents) == 0:
|
|
97
|
+
return 0
|
|
98
|
+
|
|
99
|
+
if policy == DuplicatePolicy.NONE:
|
|
100
|
+
policy = DuplicatePolicy.OVERWRITE
|
|
101
|
+
|
|
102
|
+
if policy in [DuplicatePolicy.SKIP, DuplicatePolicy.FAIL]:
|
|
103
|
+
# Fetch existing to handle SKIP/FAIL
|
|
104
|
+
existing = self._index.fetch([doc.id for doc in documents])
|
|
105
|
+
existing_ids = [res.id for res in existing if res is not None]
|
|
106
|
+
if existing_ids:
|
|
107
|
+
if policy == DuplicatePolicy.FAIL:
|
|
108
|
+
msg = f"Documents {existing_ids} already exist."
|
|
109
|
+
raise DuplicateDocumentError(msg)
|
|
110
|
+
# If SKIP, filter them out
|
|
111
|
+
documents = [doc for doc in documents if doc.id not in existing_ids]
|
|
112
|
+
if not documents:
|
|
113
|
+
return 0
|
|
114
|
+
|
|
115
|
+
vectors = []
|
|
116
|
+
for doc in documents:
|
|
117
|
+
if doc.embedding is None:
|
|
118
|
+
msg = f"Document {doc.id} must have an embedding."
|
|
119
|
+
raise DocumentStoreError(msg)
|
|
120
|
+
|
|
121
|
+
metadata = doc.meta.copy() if doc.meta else {}
|
|
122
|
+
vector_dict = {"id": doc.id, "vector": doc.embedding, "metadata": metadata}
|
|
123
|
+
if doc.content is not None:
|
|
124
|
+
vector_dict["data"] = doc.content
|
|
125
|
+
if hasattr(doc, "sparse_embedding") and doc.sparse_embedding is not None:
|
|
126
|
+
vector_dict["sparse_vector"] = (list(doc.sparse_embedding.indices), list(doc.sparse_embedding.values))
|
|
127
|
+
|
|
128
|
+
vectors.append(vector_dict)
|
|
129
|
+
|
|
130
|
+
# Upsert in batches of 1000
|
|
131
|
+
for i in range(0, len(vectors), 1000):
|
|
132
|
+
self._index.upsert(vectors=vectors[i : i + 1000])
|
|
133
|
+
|
|
134
|
+
return len(documents)
|
|
135
|
+
|
|
136
|
+
def delete_documents(self, document_ids: list[str]) -> None:
|
|
137
|
+
"""
|
|
138
|
+
Deletes documents from the Document Store by their IDs.
|
|
139
|
+
|
|
140
|
+
:param document_ids: A list of document IDs to delete.
|
|
141
|
+
"""
|
|
142
|
+
if not document_ids:
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
# Delete in batches
|
|
146
|
+
for i in range(0, len(document_ids), 1000):
|
|
147
|
+
self._index.delete(document_ids[i : i + 1000])
|
|
148
|
+
|
|
149
|
+
def filter_documents(self, filters: dict[str, Any] | None = None) -> list[Document]:
|
|
150
|
+
"""
|
|
151
|
+
Retrieves documents from the Document Store that match the given filters.
|
|
152
|
+
|
|
153
|
+
Note: Due to backend limitations, this method retrieves a maximum of 10,000 documents.
|
|
154
|
+
|
|
155
|
+
:param filters: The filters to apply.
|
|
156
|
+
:returns: A list of Documents that match the filters.
|
|
157
|
+
"""
|
|
158
|
+
filter_str = ""
|
|
159
|
+
if filters:
|
|
160
|
+
filter_str = _normalize_filters(filters)
|
|
161
|
+
|
|
162
|
+
dim = self._index.info().dimension
|
|
163
|
+
dummy_vector = [1.0] + [0.0] * (dim - 1)
|
|
164
|
+
|
|
165
|
+
results = self._index.query(
|
|
166
|
+
vector=dummy_vector,
|
|
167
|
+
top_k=TOP_K_LIMIT,
|
|
168
|
+
filter=filter_str,
|
|
169
|
+
include_metadata=True,
|
|
170
|
+
include_vectors=True,
|
|
171
|
+
include_data=True,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
if len(results) == TOP_K_LIMIT:
|
|
175
|
+
logger.warning(
|
|
176
|
+
"Upstash Vector allows a maximum of 1,000 documents to be retrieved by a filter. "
|
|
177
|
+
"The result might be truncated."
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
documents = []
|
|
181
|
+
for res in results:
|
|
182
|
+
documents.append(
|
|
183
|
+
Document(
|
|
184
|
+
id=res.id,
|
|
185
|
+
content=res.data,
|
|
186
|
+
embedding=res.vector,
|
|
187
|
+
meta=res.metadata or {},
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
return documents
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Avish Sinha <avishsinha10@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from haystack.errors import FilterError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _normalize_filters(filters: dict[str, Any]) -> str:
|
|
11
|
+
"""
|
|
12
|
+
Converts Haystack filters into Upstash Vector SQL-like filter strings.
|
|
13
|
+
"""
|
|
14
|
+
if not isinstance(filters, dict):
|
|
15
|
+
msg = "Filters must be a dictionary"
|
|
16
|
+
raise FilterError(msg)
|
|
17
|
+
|
|
18
|
+
if "field" in filters:
|
|
19
|
+
return _parse_comparison_condition(filters)
|
|
20
|
+
return _parse_logical_condition(filters)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _parse_logical_condition(condition: dict[str, Any]) -> str:
|
|
24
|
+
if "operator" not in condition:
|
|
25
|
+
msg = f"'operator' key missing in {condition}"
|
|
26
|
+
raise FilterError(msg)
|
|
27
|
+
if "conditions" not in condition:
|
|
28
|
+
msg = f"'conditions' key missing in {condition}"
|
|
29
|
+
raise FilterError(msg)
|
|
30
|
+
|
|
31
|
+
operator = condition["operator"]
|
|
32
|
+
if operator not in ["AND", "OR", "NOT"]:
|
|
33
|
+
msg = f"Unknown logical operator '{operator}'"
|
|
34
|
+
raise FilterError(msg)
|
|
35
|
+
|
|
36
|
+
parsed_conditions = [_normalize_filters(c) for c in condition["conditions"]]
|
|
37
|
+
if operator == "NOT":
|
|
38
|
+
if len(parsed_conditions) != 1:
|
|
39
|
+
msg = "NOT operator needs exactly one condition"
|
|
40
|
+
raise FilterError(msg)
|
|
41
|
+
return f"NOT ({parsed_conditions[0]})"
|
|
42
|
+
else:
|
|
43
|
+
joined = f" {operator} ".join(f"({c})" for c in parsed_conditions)
|
|
44
|
+
return joined
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _parse_comparison_condition(condition: dict[str, Any]) -> str:
|
|
48
|
+
if "field" not in condition:
|
|
49
|
+
return _parse_logical_condition(condition)
|
|
50
|
+
|
|
51
|
+
field = condition["field"]
|
|
52
|
+
if "operator" not in condition:
|
|
53
|
+
msg = f"'operator' key missing in {condition}"
|
|
54
|
+
raise FilterError(msg)
|
|
55
|
+
if "value" not in condition:
|
|
56
|
+
msg = f"'value' key missing in {condition}"
|
|
57
|
+
raise FilterError(msg)
|
|
58
|
+
|
|
59
|
+
if field.startswith("meta."):
|
|
60
|
+
field = field[5:]
|
|
61
|
+
|
|
62
|
+
operator = condition["operator"]
|
|
63
|
+
value = condition["value"]
|
|
64
|
+
|
|
65
|
+
return COMPARISON_OPERATORS[operator](field, value)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _format_value(value: Any) -> str:
|
|
69
|
+
if isinstance(value, str):
|
|
70
|
+
# Escape single quotes by doubling them
|
|
71
|
+
escaped = value.replace("'", "''")
|
|
72
|
+
return f"'{escaped}'"
|
|
73
|
+
elif isinstance(value, bool):
|
|
74
|
+
return "true" if value else "false"
|
|
75
|
+
elif isinstance(value, (int, float)):
|
|
76
|
+
return str(value)
|
|
77
|
+
msg = f"Unsupported value type {type(value)}"
|
|
78
|
+
raise FilterError(msg)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _equal(field: str, value: Any) -> str:
|
|
82
|
+
return f"{field} = {_format_value(value)}"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _not_equal(field: str, value: Any) -> str:
|
|
86
|
+
return f"{field} != {_format_value(value)}"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _greater_than(field: str, value: Any) -> str:
|
|
90
|
+
return f"{field} > {_format_value(value)}"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _greater_than_equal(field: str, value: Any) -> str:
|
|
94
|
+
return f"{field} >= {_format_value(value)}"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _less_than(field: str, value: Any) -> str:
|
|
98
|
+
return f"{field} < {_format_value(value)}"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _less_than_equal(field: str, value: Any) -> str:
|
|
102
|
+
return f"{field} <= {_format_value(value)}"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _in(field: str, value: Any) -> str:
|
|
106
|
+
if not isinstance(value, list):
|
|
107
|
+
msg = "Value for 'in' must be a list"
|
|
108
|
+
raise FilterError(msg)
|
|
109
|
+
formatted_values = ", ".join(_format_value(v) for v in value)
|
|
110
|
+
return f"{field} IN ({formatted_values})"
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _not_in(field: str, value: Any) -> str:
|
|
114
|
+
if not isinstance(value, list):
|
|
115
|
+
msg = "Value for 'not in' must be a list"
|
|
116
|
+
raise FilterError(msg)
|
|
117
|
+
formatted_values = ", ".join(_format_value(v) for v in value)
|
|
118
|
+
return f"{field} NOT IN ({formatted_values})"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
COMPARISON_OPERATORS = {
|
|
122
|
+
"==": _equal,
|
|
123
|
+
"!=": _not_equal,
|
|
124
|
+
">": _greater_than,
|
|
125
|
+
">=": _greater_than_equal,
|
|
126
|
+
"<": _less_than,
|
|
127
|
+
"<=": _less_than_equal,
|
|
128
|
+
"in": _in,
|
|
129
|
+
"not in": _not_in,
|
|
130
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: upstash-haystack
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An integration of Upstash Vector with Haystack.
|
|
5
|
+
Project-URL: Documentation, https://github.com/avish006/upstash-haystack#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/avish006/upstash-haystack/issues
|
|
7
|
+
Project-URL: Source, https://github.com/avish006/upstash-haystack
|
|
8
|
+
Author-email: Avish Sinha <avishsinha10@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: document store,haystack,hybrid search,retriever,upstash,vector database
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: haystack-ai
|
|
25
|
+
Requires-Dist: upstash-vector
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# upstash-haystack
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/upstash-haystack)
|
|
31
|
+
[](https://pypi.org/project/upstash-haystack)
|
|
32
|
+
[](https://github.com/avish006/template-repo/actions/workflows/test.yml)
|
|
33
|
+
[](https://spdx.org/licenses/Apache-2.0.html)
|
|
34
|
+
|
|
35
|
+
> **Upstash Vector** integration for [Haystack](https://haystack.deepset.ai/) — serverless, scalable vector search with zero infrastructure.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Overview
|
|
40
|
+
|
|
41
|
+
`upstash-haystack` brings [Upstash Vector](https://upstash.com/vector) into the Haystack ecosystem. Upstash Vector is a serverless, pay-as-you-go vector database with a generous free tier — no servers to provision, no clusters to manage.
|
|
42
|
+
|
|
43
|
+
### Components
|
|
44
|
+
|
|
45
|
+
| Component | Description |
|
|
46
|
+
|---|---|
|
|
47
|
+
| `UpstashDocumentStore` | Full-featured document store backed by Upstash Vector |
|
|
48
|
+
| `UpstashEmbeddingRetriever` | Dense retrieval using cosine/dot-product similarity |
|
|
49
|
+
| `UpstashHybridRetriever` | Dense + sparse hybrid search via native Reciprocal Rank Fusion (RRF) |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install upstash-haystack
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
### 1. Create an Upstash Vector index
|
|
64
|
+
|
|
65
|
+
Sign up at [console.upstash.com](https://console.upstash.com/) and create a Vector index. Copy the **REST URL** and **REST Token** from the dashboard.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
export UPSTASH_VECTOR_REST_URL="https://your-endpoint.upstash.io"
|
|
69
|
+
export UPSTASH_VECTOR_REST_TOKEN="your-token"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 2. Dense (Embedding) Retrieval
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from haystack import Document, Pipeline
|
|
76
|
+
from haystack_integrations.document_stores.upstash import UpstashDocumentStore
|
|
77
|
+
from haystack_integrations.components.retrievers.upstash import UpstashEmbeddingRetriever
|
|
78
|
+
|
|
79
|
+
# Initialize the document store (reads credentials from env vars)
|
|
80
|
+
document_store = UpstashDocumentStore()
|
|
81
|
+
|
|
82
|
+
# Write documents with embeddings
|
|
83
|
+
docs = [
|
|
84
|
+
Document(content="The capital of France is Paris.", embedding=[0.1, 0.2, ...]),
|
|
85
|
+
Document(content="The capital of Germany is Berlin.", embedding=[0.4, 0.5, ...]),
|
|
86
|
+
]
|
|
87
|
+
document_store.write_documents(docs)
|
|
88
|
+
|
|
89
|
+
# Retrieve the top-k most similar documents
|
|
90
|
+
retriever = UpstashEmbeddingRetriever(document_store=document_store)
|
|
91
|
+
result = retriever.run(query_embedding=[0.1, 0.2, ...], top_k=1)
|
|
92
|
+
print(result["documents"])
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Hybrid Retrieval (Dense + Sparse)
|
|
96
|
+
|
|
97
|
+
Upstash Vector natively supports hybrid search via Reciprocal Rank Fusion (RRF), combining dense and sparse signals for superior relevance.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from haystack.dataclasses import SparseEmbedding
|
|
101
|
+
from haystack_integrations.components.retrievers.upstash import UpstashHybridRetriever
|
|
102
|
+
|
|
103
|
+
retriever = UpstashHybridRetriever(document_store=document_store)
|
|
104
|
+
|
|
105
|
+
result = retriever.run(
|
|
106
|
+
query_embedding=[0.1, 0.2, ...],
|
|
107
|
+
query_sparse_embedding=SparseEmbedding(indices=[0, 5, 12], values=[0.9, 0.4, 0.2]),
|
|
108
|
+
top_k=5,
|
|
109
|
+
)
|
|
110
|
+
print(result["documents"])
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 4. Filtering
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# Equality filter
|
|
117
|
+
docs = document_store.filter_documents(
|
|
118
|
+
filters={"field": "meta.category", "operator": "==", "value": "science"}
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# AND operator
|
|
122
|
+
docs = document_store.filter_documents(
|
|
123
|
+
filters={
|
|
124
|
+
"operator": "AND",
|
|
125
|
+
"conditions": [
|
|
126
|
+
{"field": "meta.category", "operator": "==", "value": "science"},
|
|
127
|
+
{"field": "meta.year", "operator": ">", "value": 2020},
|
|
128
|
+
],
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Configuration
|
|
136
|
+
|
|
137
|
+
The document store is configured via environment variables or explicit `Secret` objects:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from haystack.utils.auth import Secret
|
|
141
|
+
from haystack_integrations.document_stores.upstash import UpstashDocumentStore
|
|
142
|
+
|
|
143
|
+
store = UpstashDocumentStore(
|
|
144
|
+
url=Secret.from_env_var("UPSTASH_VECTOR_REST_URL"),
|
|
145
|
+
token=Secret.from_env_var("UPSTASH_VECTOR_REST_TOKEN"),
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Development
|
|
152
|
+
|
|
153
|
+
This project uses [Hatch](https://hatch.pypa.io/) for environment and dependency management.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Format and lint
|
|
157
|
+
hatch run fmt
|
|
158
|
+
|
|
159
|
+
# Type checking
|
|
160
|
+
hatch run test:types
|
|
161
|
+
|
|
162
|
+
# Unit tests (mocked, no credentials needed)
|
|
163
|
+
hatch run test:unit
|
|
164
|
+
|
|
165
|
+
# Integration tests (requires live Upstash credentials)
|
|
166
|
+
export UPSTASH_VECTOR_REST_URL="..."
|
|
167
|
+
export UPSTASH_VECTOR_REST_TOKEN="..."
|
|
168
|
+
hatch run test:integration
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
`upstash-haystack` is distributed under the terms of the [Apache 2.0](https://spdx.org/licenses/Apache-2.0.html) license.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
haystack_integrations/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
haystack_integrations/components/retrievers/upstash/__init__.py,sha256=vpLBmA11UL9dtLhc2--lOiKYYQkOjemd6JC5-fysWxc,296
|
|
3
|
+
haystack_integrations/components/retrievers/upstash/embedding_retriever.py,sha256=2_aQgLNyt8jVbH0aLJDJh-xBiHq54WWclk0cVgPCPYw,3425
|
|
4
|
+
haystack_integrations/components/retrievers/upstash/hybrid_retriever.py,sha256=ArR8rXeJE3ZesWM06i6zMapj6pvGHJ3empGn-2v4LI4,3831
|
|
5
|
+
haystack_integrations/document_stores/upstash/__init__.py,sha256=_zjAAJFpFcRO_6UEO6O7Eu6YsxciZlc__esCvNou5Hk,202
|
|
6
|
+
haystack_integrations/document_stores/upstash/document_store.py,sha256=ojNq0XjvpIgZJJiEVuRGNRi-_UEGtoJAp_Ml02N2HeE,6824
|
|
7
|
+
haystack_integrations/document_stores/upstash/filters.py,sha256=XKf2MZoo6q63XHTAv5KB8NerGhFz8sOb-uYQJjwXOWM,3825
|
|
8
|
+
upstash_haystack-0.1.0.dist-info/METADATA,sha256=Ae5q2plxl6zqBwkiV3F8PWPJeOR1d9DYfJVVTuRGOz0,5749
|
|
9
|
+
upstash_haystack-0.1.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
10
|
+
upstash_haystack-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
+
upstash_haystack-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|