@@ -16,7 +16,7 @@ class QdrantConfig(BaseModel):
|
|||||||
path: Optional[str] = Field("/tmp/qdrant", description="Path for local Qdrant database")
|
path: Optional[str] = Field("/tmp/qdrant", description="Path for local Qdrant database")
|
||||||
url: Optional[str] = Field(None, description="Full URL for Qdrant server")
|
url: Optional[str] = Field(None, description="Full URL for Qdrant server")
|
||||||
api_key: Optional[str] = Field(None, description="API key for Qdrant server")
|
api_key: Optional[str] = Field(None, description="API key for Qdrant server")
|
||||||
on_disk: Optional[bool] = Field(False, description="Enables persistent storage")
|
on_disk: Optional[bool] = Field(False,description="Enables persistent storage. Vectors are kept on disk (True) or in memory (False). Does not delete the local database path.")
|
||||||
|
|
||||||
@model_validator(mode="before")
|
@model_validator(mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from qdrant_client import QdrantClient
|
from qdrant_client import QdrantClient
|
||||||
@@ -48,7 +46,8 @@ class Qdrant(VectorStoreBase):
|
|||||||
path (str, optional): Path for local Qdrant database. Defaults to None.
|
path (str, optional): Path for local Qdrant database. Defaults to None.
|
||||||
url (str, optional): Full URL for Qdrant server. Defaults to None.
|
url (str, optional): Full URL for Qdrant server. Defaults to None.
|
||||||
api_key (str, optional): API key for Qdrant server. Defaults to None.
|
api_key (str, optional): API key for Qdrant server. Defaults to None.
|
||||||
on_disk (bool, optional): Enables persistent storage. Defaults to False.
|
on_disk (bool, optional): Enables persistent storage. Vectors are stored on disk (True) or in memory (False).
|
||||||
|
Does not delete the local database path. Defaults to False.
|
||||||
"""
|
"""
|
||||||
if client:
|
if client:
|
||||||
self.client = client
|
self.client = client
|
||||||
@@ -66,9 +65,6 @@ class Qdrant(VectorStoreBase):
|
|||||||
if not params:
|
if not params:
|
||||||
params["path"] = path
|
params["path"] = path
|
||||||
self.is_local = True
|
self.is_local = True
|
||||||
if not on_disk:
|
|
||||||
if os.path.exists(path) and os.path.isdir(path):
|
|
||||||
shutil.rmtree(path)
|
|
||||||
else:
|
else:
|
||||||
self.is_local = False
|
self.is_local = False
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import os
|
||||||
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import uuid
|
import uuid
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from qdrant_client import QdrantClient
|
from qdrant_client import QdrantClient
|
||||||
from qdrant_client.models import (
|
from qdrant_client.models import (
|
||||||
@@ -31,6 +33,23 @@ class TestQdrant(unittest.TestCase):
|
|||||||
on_disk=True,
|
on_disk=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_local_path_on_disk_false_preserves_existing_directory(self):
|
||||||
|
"""#4473: local path must not be removed when on_disk is False."""
|
||||||
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
sentinel = os.path.join(tmp, "sentinel")
|
||||||
|
with open(sentinel, "w", encoding="utf-8") as f:
|
||||||
|
f.write("keep")
|
||||||
|
mock_client = MagicMock()
|
||||||
|
mock_client.get_collections.return_value = MagicMock(collections=[])
|
||||||
|
with patch("mem0.vector_stores.qdrant.QdrantClient", return_value=mock_client):
|
||||||
|
Qdrant(
|
||||||
|
collection_name="c",
|
||||||
|
embedding_model_dims=128,
|
||||||
|
path=tmp,
|
||||||
|
on_disk=False,
|
||||||
|
)
|
||||||
|
self.assertTrue(os.path.isfile(sentinel))
|
||||||
|
|
||||||
def test_create_col(self):
|
def test_create_col(self):
|
||||||
self.client_mock.get_collections.return_value = MagicMock(collections=[])
|
self.client_mock.get_collections.return_value = MagicMock(collections=[])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user