Skip to content
Open
10 changes: 3 additions & 7 deletions llama-index-core/llama_index/core/base/llms/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,16 +549,12 @@ def from_str(

def _recursive_serialization(self, value: Any) -> Any:
if isinstance(value, BaseModel):
value.model_rebuild() # ensures all fields are initialized and serializable
return value.model_dump() # type: ignore
value.model_rebuild()
return value.model_dump()
if isinstance(value, dict):
return {
key: self._recursive_serialization(value)
for key, value in value.items()
}
return {k: self._recursive_serialization(v) for k, v in value.items()}
if isinstance(value, list):
return [self._recursive_serialization(item) for item in value]

if isinstance(value, bytes):
return base64.b64encode(value).decode("utf-8")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ requires-python = ">=3.11,<=3.13"
readme = "README.md"
license = "MIT"
dependencies = [
"cognee[neo4j, postgres, qdrant]",
"cognee[neo4j, postgres, qdrant]==0.1.26",
"httpx~=0.27.0",
"graphistry",
"llama-index-core>=0.13.0,<0.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,30 +182,29 @@ def _create_vector_index(self, table_name: str) -> None:
if not self.use_vector_index or table_name != "Chunk":
return

# Check if chunk_embedding_index already exists
existing_indexes_result = self.connection.execute(
"CALL SHOW_INDEXES() RETURN *"
)
for row in existing_indexes_result:
if len(row) > 1 and row[1] == "chunk_embedding_index":
if "embedding" in str(row):
return

# Check if table has any data - Kuzu requires data before creating vector index
count_result = self.connection.execute(
f"MATCH (n:{table_name}) RETURN COUNT(n)"
)
if not any(int(row[0]) > 0 for row in count_result):
return

# Create vector index for Chunk table
self.connection.execute("""
CALL CREATE_VECTOR_INDEX(
'Chunk',
'chunk_embedding_index',
'embedding',
metric := 'cosine'
)
""")
CALL CREATE_VECTOR_INDEX(
'Chunk',
'embedding',
USING {
metric_type: 'COSINE',
index_type: 'HNSW'
}
)
""")

def _ensure_vector_indexes(self) -> None:
"""Ensure vector indexes are created for Chunk table only."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ def search(self, query: str, **kwargs) -> Optional[Dict[str, Any]]:


class Mem0Context(BaseModel):
user_id: Optional[str] = None
agent_id: Optional[str] = None
run_id: Optional[str] = None
user_id: Optional[str] = Field(default=None, description="User ID")
agent_id: Optional[str] = Field(default=None, description="Agent ID")
run_id: Optional[str] = Field(default=None, description="Run ID")

@model_validator(mode="after")
@model_validator(mode="before")
def check_at_least_one_assigned(cls, values):
if not any(
getattr(values, field) for field in ["user_id", "agent_id", "run_id"]
):
if not any(values.get(field) for field in ["user_id", "agent_id", "run_id"]):
raise ValueError(
"At least one of 'user_id', 'agent_id', or 'run_id' must be assigned."
)
Expand Down Expand Up @@ -142,10 +140,7 @@ def from_config(
):
primary_memory = LlamaIndexMemory.from_defaults()

try:
context = Mem0Context(**context)
except Exception as e:
raise ValidationError(f"Context validation error: {e}")
context = Mem0Context(**context)

client = Memory.from_config(config_dict=config)
return cls(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from unittest.mock import MagicMock, AsyncMock

from unittest.mock import MagicMock, AsyncMock, patch
import pytest
import sys

Expand Down Expand Up @@ -30,12 +29,15 @@
("urls", "additional_params", "return_value", "expected_output"),
[READER_TEST_PARAM],
)
@patch("llama_index.readers.web.oxylabs_web.base.version")
def test_sync_oxylabs_reader(
mock_version: MagicMock,
urls: list[str],
additional_params: dict,
return_value: dict,
expected_output: str,
):
mock_version.return_value = "0.1.0"
reader = OxylabsWebReader(
username="OXYLABS_USERNAME",
password="OXYLABS_PASSWORD",
Expand All @@ -57,12 +59,15 @@ def test_sync_oxylabs_reader(
[READER_TEST_PARAM],
)
@pytest.mark.asyncio
@patch("llama_index.readers.web.oxylabs_web.base.version")
async def test_async_oxylabs_reader(
mock_version: MagicMock,
urls: list[str],
additional_params: dict,
return_value: dict,
expected_output: str,
):
mock_version.return_value = "0.1.0"
reader = OxylabsWebReader(
username="OXYLABS_USERNAME",
password="OXYLABS_PASSWORD",
Expand Down
Loading
Loading