fix: Databricks Vector Store (#3546)
This commit is contained in:
@@ -589,7 +589,8 @@ class Databricks(VectorStoreBase):
|
|||||||
raise KeyError(f"Vector with ID {vector_id} not found")
|
raise KeyError(f"Vector with ID {vector_id} not found")
|
||||||
|
|
||||||
result = data_array[0]
|
result = data_array[0]
|
||||||
row_data = result if isinstance(result, dict) else result.__dict__
|
columns = columns = [col.name for col in results.manifest.columns] if results.manifest and results.manifest.columns else []
|
||||||
|
row_data = dict(zip(columns, result))
|
||||||
|
|
||||||
# Build payload following the standard schema
|
# Build payload following the standard schema
|
||||||
payload = {
|
payload = {
|
||||||
@@ -608,7 +609,7 @@ class Databricks(VectorStoreBase):
|
|||||||
payload[field] = row_data[field]
|
payload[field] = row_data[field]
|
||||||
|
|
||||||
# Add metadata
|
# Add metadata
|
||||||
if "metadata" in row_data:
|
if "metadata" in row_data and row_data.get('metadata'):
|
||||||
try:
|
try:
|
||||||
metadata = json.loads(extract_json(row_data["metadata"]))
|
metadata = json.loads(extract_json(row_data["metadata"]))
|
||||||
payload.update(metadata)
|
payload.update(metadata)
|
||||||
@@ -707,6 +708,7 @@ class Databricks(VectorStoreBase):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
memory_id = row_dict.get("memory_id") or row_dict.get("id")
|
memory_id = row_dict.get("memory_id") or row_dict.get("id")
|
||||||
|
payload['data'] = payload['memory']
|
||||||
memory_results.append(MemoryResult(id=memory_id, payload=payload))
|
memory_results.append(MemoryResult(id=memory_id, payload=payload))
|
||||||
return [memory_results]
|
return [memory_results]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
from databricks.sdk.service.vectorsearch import VectorIndexType
|
from databricks.sdk.service.vectorsearch import VectorIndexType, QueryVectorIndexResponse, ResultManifest, ResultData, ColumnInfo
|
||||||
from mem0.vector_stores.databricks import Databricks
|
from mem0.vector_stores.databricks import Databricks
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -241,21 +241,33 @@ def test_update_vector(db_instance_direct, mock_workspace_client):
|
|||||||
|
|
||||||
|
|
||||||
def test_get_vector(db_instance_delta, mock_workspace_client):
|
def test_get_vector(db_instance_delta, mock_workspace_client):
|
||||||
mock_workspace_client.vector_search_indexes.query_index.return_value = SimpleNamespace(
|
mock_workspace_client.vector_search_indexes.query_index.return_value = QueryVectorIndexResponse(
|
||||||
result=SimpleNamespace(
|
manifest=ResultManifest(columns=[
|
||||||
|
ColumnInfo(name="memory_id"),
|
||||||
|
ColumnInfo(name="hash"),
|
||||||
|
ColumnInfo(name="agent_id"),
|
||||||
|
ColumnInfo(name="run_id"),
|
||||||
|
ColumnInfo(name="user_id"),
|
||||||
|
ColumnInfo(name="memory"),
|
||||||
|
ColumnInfo(name="metadata"),
|
||||||
|
ColumnInfo(name="created_at"),
|
||||||
|
ColumnInfo(name="updated_at"),
|
||||||
|
ColumnInfo(name="score"),
|
||||||
|
]),
|
||||||
|
result=ResultData(
|
||||||
data_array=[
|
data_array=[
|
||||||
{
|
[
|
||||||
"memory_id": "id-get",
|
"id-get",
|
||||||
"hash": "h",
|
"h",
|
||||||
"agent_id": "a",
|
"a",
|
||||||
"run_id": "r",
|
"r",
|
||||||
"user_id": "u",
|
"u",
|
||||||
"memory": "some memory",
|
"some memory",
|
||||||
"metadata": '{"tag":"x"}',
|
'{"tag":"x"}',
|
||||||
"created_at": "2024-01-01T00:00:00",
|
"2024-01-01T00:00:00",
|
||||||
"updated_at": "2024-01-01T00:00:00",
|
"2024-01-01T00:00:00",
|
||||||
"score": 0.99,
|
"0.99",
|
||||||
}
|
]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -284,25 +296,40 @@ def test_col_info(db_instance_delta):
|
|||||||
|
|
||||||
|
|
||||||
def test_list_memories(db_instance_delta, mock_workspace_client):
|
def test_list_memories(db_instance_delta, mock_workspace_client):
|
||||||
row = {
|
mock_workspace_client.vector_search_indexes.query_index.return_value = QueryVectorIndexResponse(
|
||||||
"memory_id": "id3",
|
manifest=ResultManifest(columns=[
|
||||||
"hash": "hash3",
|
ColumnInfo(name="memory_id"),
|
||||||
"agent_id": "agent3",
|
ColumnInfo(name="hash"),
|
||||||
"run_id": "run3",
|
ColumnInfo(name="agent_id"),
|
||||||
"user_id": "user3",
|
ColumnInfo(name="run_id"),
|
||||||
"memory": "memory three",
|
ColumnInfo(name="user_id"),
|
||||||
"metadata": '{"topic":"misc"}',
|
ColumnInfo(name="memory"),
|
||||||
"created_at": "2024-01-03T00:00:00",
|
ColumnInfo(name="metadata"),
|
||||||
"updated_at": "2024-01-03T00:00:00",
|
ColumnInfo(name="created_at"),
|
||||||
"score": 0.33,
|
ColumnInfo(name="updated_at"),
|
||||||
}
|
ColumnInfo(name="score"),
|
||||||
mock_workspace_client.vector_search_indexes.query_index.return_value = SimpleNamespace(
|
]),
|
||||||
result=SimpleNamespace(data_array=[row])
|
result=ResultData(
|
||||||
|
data_array=[
|
||||||
|
[
|
||||||
|
"id-get",
|
||||||
|
"h",
|
||||||
|
"a",
|
||||||
|
"r",
|
||||||
|
"u",
|
||||||
|
"some memory",
|
||||||
|
'{"tag":"x"}',
|
||||||
|
"2024-01-01T00:00:00",
|
||||||
|
"2024-01-01T00:00:00",
|
||||||
|
"0.99",
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
res = db_instance_delta.list(limit=1)
|
res = db_instance_delta.list(limit=1)
|
||||||
assert isinstance(res, list)
|
assert isinstance(res, list)
|
||||||
assert len(res[0]) == 1
|
assert len(res[0]) == 1
|
||||||
assert res[0][0].id == "id3"
|
assert res[0][0].id == "id-get"
|
||||||
|
|
||||||
|
|
||||||
# ---------------------- Reset Tests ---------------------- #
|
# ---------------------- Reset Tests ---------------------- #
|
||||||
|
|||||||
Reference in New Issue
Block a user