|
1 | 1 | import inspect |
| 2 | +from copy import deepcopy |
2 | 3 | from itertools import islice |
3 | 4 | from typing import Any, AsyncGenerator, ClassVar, Dict, Generator, List, Optional, Set, Tuple, Union |
4 | 5 |
|
|
18 | 19 | from .converters import ( |
19 | 20 | DENSE_VECTORS_NAME, |
20 | 21 | SPARSE_VECTORS_NAME, |
| 22 | + QdrantPoint, |
21 | 23 | convert_haystack_documents_to_qdrant_points, |
22 | 24 | convert_id, |
23 | 25 | convert_qdrant_point_to_haystack_document, |
24 | | - QdrantPoint |
25 | 26 | ) |
26 | 27 | from .filters import convert_filters_to_qdrant |
27 | 28 |
|
@@ -131,7 +132,7 @@ def __init__( |
131 | 132 | ) -> None: |
132 | 133 | """ |
133 | 134 | :param location: |
134 | | - If `memory` - use in-memory Qdrant instance. |
| 135 | + If `":memory:"` - use in-memory Qdrant instance. |
135 | 136 | If `str` - use it as a URL parameter. |
136 | 137 | If `None` - use default values for host and port. |
137 | 138 | :param url: |
@@ -261,6 +262,7 @@ def __init__( |
261 | 262 | def _initialize_client(self) -> None: |
262 | 263 | if self._client is None: |
263 | 264 | client_params = self._prepare_client_params() |
| 265 | + # This step adds the api-key and User-Agent to metadata |
264 | 266 | self._client = qdrant_client.QdrantClient(**client_params) |
265 | 267 | # Make sure the collection is properly set up |
266 | 268 | self._set_up_collection( |
@@ -1538,21 +1540,26 @@ def _prepare_client_params(self) -> Dict[str, Any]: |
1538 | 1540 | Prepares the common parameters for client initialization. |
1539 | 1541 |
|
1540 | 1542 | """ |
1541 | | - return { |
1542 | | - "location": self.location, |
1543 | | - "url": self.url, |
1544 | | - "port": self.port, |
1545 | | - "grpc_port": self.grpc_port, |
1546 | | - "prefer_grpc": self.prefer_grpc, |
1547 | | - "https": self.https, |
1548 | | - "api_key": self.api_key.resolve_value() if self.api_key else None, |
1549 | | - "prefix": self.prefix, |
1550 | | - "timeout": self.timeout, |
1551 | | - "host": self.host, |
1552 | | - "path": self.path, |
1553 | | - "metadata": self.metadata, |
1554 | | - "force_disable_check_same_thread": self.force_disable_check_same_thread, |
1555 | | - } |
| 1543 | + # NOTE: We need to use deepcopy here to avoid modifying the original class attributes. |
| 1544 | + # For example, the resolved api key is added to metadata by the QdrantClient class when using a hosted |
| 1545 | + # Qdrant service, which means running to_dict() exposes the api key. |
| 1546 | + return deepcopy( |
| 1547 | + { |
| 1548 | + "location": self.location, |
| 1549 | + "url": self.url, |
| 1550 | + "port": self.port, |
| 1551 | + "grpc_port": self.grpc_port, |
| 1552 | + "prefer_grpc": self.prefer_grpc, |
| 1553 | + "https": self.https, |
| 1554 | + "api_key": self.api_key.resolve_value() if self.api_key else None, |
| 1555 | + "prefix": self.prefix, |
| 1556 | + "timeout": self.timeout, |
| 1557 | + "host": self.host, |
| 1558 | + "path": self.path, |
| 1559 | + "metadata": self.metadata, |
| 1560 | + "force_disable_check_same_thread": self.force_disable_check_same_thread, |
| 1561 | + } |
| 1562 | + ) |
1556 | 1563 |
|
1557 | 1564 | def _prepare_collection_config( |
1558 | 1565 | self, |
|
0 commit comments