Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "weaviate-engram"
version = "0.2.0"
version = "0.3.0"
description = "Python SDK for Engram by Weaviate."
readme = "README.md"
requires-python = ">=3.11,<3.15"
Expand Down
4 changes: 2 additions & 2 deletions src/engram/_models/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class ConversationContent:

@dataclass(slots=True)
class RetrievalConfig:
retrieval_type: Literal["vector", "bm25", "hybrid"] = "hybrid"
limit: int = 10
retrieval_type: Literal["vector", "bm25", "hybrid"]
limit: int | None = None


@dataclass(slots=True)
Expand Down
4 changes: 2 additions & 2 deletions src/engram/_resources/memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def search(
user_id=user_id,
conversation_id=conversation_id,
group=group,
retrieval_config=retrieval_config or RetrievalConfig(),
retrieval_config=retrieval_config,
)
data = self._transport.request("POST", _MEMORIES_SEARCH_PATH, json=body)
return parse_search_results(data)
Expand Down Expand Up @@ -159,7 +159,7 @@ async def search(
user_id=user_id,
conversation_id=conversation_id,
group=group,
retrieval_config=retrieval_config or RetrievalConfig(),
retrieval_config=retrieval_config,
)
data = await self._transport.request("POST", _MEMORIES_SEARCH_PATH, json=body)
return parse_search_results(data)
11 changes: 5 additions & 6 deletions src/engram/_serialization/_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,14 @@ def build_search_body(
user_id: str | None,
conversation_id: str | None,
group: str | None,
retrieval_config: RetrievalConfig,
retrieval_config: RetrievalConfig | None,
) -> dict[str, Any]:
body: dict[str, Any] = {
"query": query,
"retrieval_config": {
body: dict[str, Any] = {"query": query}
if retrieval_config is not None:
body["retrieval_config"] = {
"retrieval_type": retrieval_config.retrieval_type,
"limit": retrieval_config.limit,
},
}
}
if topics is not None:
body["topics"] = topics
if user_id is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/engram/_serialization/_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def parse_memory(data: dict[str, Any]) -> Memory:

def parse_search_results(data: dict[str, Any]) -> SearchResults:
return SearchResults(
memories=[parse_memory(m["Body"]) for m in data["memories"]],
memories=[parse_memory(m) for m in data["memories"]],
total=data["total"],
)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async def test_delete_memory() -> None:
@pytest.mark.asyncio
async def test_search_memories() -> None:
response_body: dict[str, Any] = {
"memories": [{"Body": SAMPLE_MEMORY_RESPONSE}],
"memories": [SAMPLE_MEMORY_RESPONSE],
"total": 1,
}
client = _make_client(body=response_body)
Expand All @@ -283,8 +283,8 @@ async def test_search_memories() -> None:
async def test_search_memories_iterable() -> None:
response_body: dict[str, Any] = {
"memories": [
{"Body": SAMPLE_MEMORY_RESPONSE},
{"Body": {**SAMPLE_MEMORY_RESPONSE, "id": "m2", "score": 0.85}},
SAMPLE_MEMORY_RESPONSE,
{**SAMPLE_MEMORY_RESPONSE, "id": "m2", "score": 0.85},
],
"total": 2,
}
Expand Down
13 changes: 5 additions & 8 deletions tests/test_client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_delete_memory() -> None:

def test_search_memories() -> None:
response_body: dict[str, Any] = {
"memories": [{"Body": SAMPLE_MEMORY_RESPONSE}],
"memories": [SAMPLE_MEMORY_RESPONSE],
"total": 1,
}
client = _make_client(body=response_body)
Expand All @@ -293,8 +293,8 @@ def test_search_memories() -> None:
def test_search_memories_iterable() -> None:
response_body: dict[str, Any] = {
"memories": [
{"Body": SAMPLE_MEMORY_RESPONSE},
{"Body": {**SAMPLE_MEMORY_RESPONSE, "id": "m2", "score": 0.85}},
SAMPLE_MEMORY_RESPONSE,
{**SAMPLE_MEMORY_RESPONSE, "id": "m2", "score": 0.85},
],
"total": 2,
}
Expand Down Expand Up @@ -325,7 +325,7 @@ def handler(request: httpx.Request) -> httpx.Response:
assert body["retrieval_config"]["limit"] == 5


def test_search_default_retrieval_config() -> None:
def test_search_no_retrieval_config_by_default() -> None:
captured: list[httpx.Request] = []

def handler(request: httpx.Request) -> httpx.Response:
Expand All @@ -335,10 +335,7 @@ def handler(request: httpx.Request) -> httpx.Response:
client = _make_client_with_handler(handler)
client.memories.search(query="test")
body = json.loads(captured[0].content)
assert body["retrieval_config"] == {
"retrieval_type": "hybrid",
"limit": 10,
}
assert "retrieval_config" not in body


# ── runs.get ────────────────────────────────────────────────────────────
Expand Down
11 changes: 4 additions & 7 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,9 @@ def test_build_search_body_defaults() -> None:
user_id=None,
conversation_id=None,
group=None,
retrieval_config=RetrievalConfig(),
retrieval_config=None,
)
assert body == {
"query": "test",
"retrieval_config": {"retrieval_type": "hybrid", "limit": 10},
}
assert body == {"query": "test"}


def test_build_search_body_full() -> None:
Expand Down Expand Up @@ -282,7 +279,7 @@ def test_parse_memory_with_optional_fields() -> None:


def test_parse_search_results() -> None:
data = {"memories": [{"Body": SAMPLE_MEMORY}], "total": 1}
data = {"memories": [SAMPLE_MEMORY], "total": 1}
result = parse_search_results(data)
assert result.total == 1
assert len(result) == 1
Expand All @@ -297,7 +294,7 @@ def test_parse_search_results_empty() -> None:

def test_search_results_iterable() -> None:
data = {
"memories": [{"Body": SAMPLE_MEMORY}, {"Body": {**SAMPLE_MEMORY, "id": "m2"}}],
"memories": [SAMPLE_MEMORY, {**SAMPLE_MEMORY, "id": "m2"}],
"total": 2,
}
result = parse_search_results(data)
Expand Down
Loading