Skip to content

Commit

Permalink
refactor!: Qdrant - update secret management (#405)
Browse files Browse the repository at this point in the history
* refactor!: Qdrant - update secret management

* Linting
  • Loading branch information
shadeMe authored Feb 14, 2024
1 parent 613e4ec commit e7e3ece
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integrations/qdrant/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = ["haystack-ai", "qdrant-client"]
dependencies = ["haystack-ai>=2.0.0b6", "qdrant-client"]

[project.urls]
Source = "https://github.com/deepset-ai/haystack-core-integrations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from haystack.dataclasses import Document
from haystack.document_stores.errors import DocumentStoreError, DuplicateDocumentError
from haystack.document_stores.types import DuplicatePolicy
from haystack.utils import Secret, deserialize_secrets_inplace
from haystack.utils.filters import convert
from qdrant_client import grpc
from qdrant_client.http import models as rest
Expand Down Expand Up @@ -55,7 +56,7 @@ def __init__(
grpc_port: int = 6334,
prefer_grpc: bool = False, # noqa: FBT001, FBT002
https: Optional[bool] = None,
api_key: Optional[str] = None,
api_key: Optional[Secret] = None,
prefix: Optional[str] = None,
timeout: Optional[float] = None,
host: Optional[str] = None,
Expand Down Expand Up @@ -94,7 +95,7 @@ def __init__(
grpc_port=grpc_port,
prefer_grpc=prefer_grpc,
https=https,
api_key=api_key,
api_key=api_key.resolve_value() if api_key else None,
prefix=prefix,
timeout=timeout,
host=host,
Expand All @@ -115,6 +116,7 @@ def __init__(
self.host = host
self.path = path
self.metadata = metadata
self.api_key = api_key

# Store the Qdrant collection specific attributes
self.shard_number = shard_number
Expand Down Expand Up @@ -232,13 +234,15 @@ def delete_documents(self, ids: List[str]):

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "QdrantDocumentStore":
deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
return default_from_dict(cls, data)

def to_dict(self) -> Dict[str, Any]:
params = inspect.signature(self.__init__).parameters # type: ignore
# All the __init__ params must be set as attributes
# Set as init_parms without default values
init_params = {k: getattr(self, k) for k in params}
init_params["api_key"] = self.api_key.to_dict() if self.api_key else None
return default_to_dict(
self,
**init_params,
Expand Down
3 changes: 3 additions & 0 deletions integrations/qdrant/tests/test_dict_converters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from haystack.utils import Secret
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore


Expand Down Expand Up @@ -52,6 +53,7 @@ def test_from_dict():
{
"type": "haystack_integrations.document_stores.qdrant.document_store.QdrantDocumentStore",
"init_parameters": {
"api_key": {"env_vars": ["ENV_VAR"], "strict": False, "type": "env_var"},
"location": ":memory:",
"index": "test",
"embedding_dim": 768,
Expand Down Expand Up @@ -98,5 +100,6 @@ def test_from_dict():
document_store.metadata == {},
document_store.write_batch_size == 1000,
document_store.scroll_size == 10000,
document_store.api_key == Secret.from_env_var("ENV_VAR", strict=False),
]
)

0 comments on commit e7e3ece

Please sign in to comment.