mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
Allow long relation_type values in responses
Signed-off-by: phernandez <paul@basicmachines.co>
This commit is contained in:
@@ -178,8 +178,13 @@ ContentType = Annotated[
|
||||
]
|
||||
|
||||
|
||||
RelationType = Annotated[str, MinLen(1), MaxLen(200)]
|
||||
"""Type of relationship between entities. Always use active voice present tense."""
|
||||
RelationType = Annotated[str, MinLen(1)]
|
||||
"""Type of relationship between entities. Always use active voice present tense.
|
||||
|
||||
The database stores relation_type as an unrestricted string, and response models
|
||||
need to tolerate existing long-form values written by LLMs. Keeping an API-only
|
||||
200-character cap here causes reads to fail for valid stored data.
|
||||
"""
|
||||
|
||||
ObservationStr = Annotated[
|
||||
str,
|
||||
|
||||
@@ -137,6 +137,58 @@ async def test_get_entity_by_id(client: AsyncClient, test_graph, v2_project_url,
|
||||
assert entity.api_version == "v2"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_entity_by_id_allows_long_relation_type(
|
||||
client: AsyncClient,
|
||||
v2_project_url,
|
||||
relation_repository,
|
||||
):
|
||||
"""GET entity should not fail when stored relation_type exceeds 200 characters."""
|
||||
source_response = await client.post(
|
||||
f"{v2_project_url}/knowledge/entities",
|
||||
json={
|
||||
"title": "Long Relation Source",
|
||||
"directory": "test",
|
||||
"content": "Source entity content",
|
||||
},
|
||||
)
|
||||
assert source_response.status_code == 200
|
||||
source_entity = EntityResponseV2.model_validate(source_response.json())
|
||||
|
||||
target_response = await client.post(
|
||||
f"{v2_project_url}/knowledge/entities",
|
||||
json={
|
||||
"title": "Long Relation Target",
|
||||
"directory": "test",
|
||||
"content": "Target entity content",
|
||||
},
|
||||
)
|
||||
assert target_response.status_code == 200
|
||||
target_entity = EntityResponseV2.model_validate(target_response.json())
|
||||
|
||||
long_relation_type = (
|
||||
"**Architecture/efficiency concern:** "
|
||||
"the orchestration prompt expanded a short edge label into a full descriptive note "
|
||||
"that is much longer than 200 characters but should still serialize cleanly."
|
||||
)
|
||||
|
||||
await relation_repository.create(
|
||||
{
|
||||
"from_id": source_entity.id,
|
||||
"to_id": target_entity.id,
|
||||
"to_name": target_entity.title,
|
||||
"relation_type": long_relation_type,
|
||||
}
|
||||
)
|
||||
|
||||
response = await client.get(f"{v2_project_url}/knowledge/entities/{source_entity.external_id}")
|
||||
|
||||
assert response.status_code == 200
|
||||
entity = EntityResponseV2.model_validate(response.json())
|
||||
assert len(entity.relations) == 1
|
||||
assert entity.relations[0].relation_type == long_relation_type
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_entity_by_id_not_found(client: AsyncClient, v2_project_url):
|
||||
"""Test getting a non-existent entity by external_id returns 404."""
|
||||
|
||||
@@ -91,6 +91,26 @@ def test_relation_response():
|
||||
assert relation.context is None
|
||||
|
||||
|
||||
def test_relation_response_allows_long_relation_type():
|
||||
"""Long relation labels should round-trip because stored data has no DB length cap."""
|
||||
long_relation_type = (
|
||||
"**Architecture/efficiency concern:** "
|
||||
"the orchestration prompt expanded a short edge label into a full descriptive note "
|
||||
"that is much longer than 200 characters but still represents the stored relation type."
|
||||
)
|
||||
data = {
|
||||
"permalink": "test/123/long/test/456",
|
||||
"from_id": "test/123",
|
||||
"to_id": "test/456",
|
||||
"relation_type": long_relation_type,
|
||||
"from_entity": {"permalink": "test/123"},
|
||||
"to_entity": {"permalink": "test/456"},
|
||||
}
|
||||
|
||||
relation = RelationResponse.model_validate(data)
|
||||
assert relation.relation_type == long_relation_type
|
||||
|
||||
|
||||
def test_relation_response_with_null_permalink():
|
||||
"""Test RelationResponse handles null permalinks by falling back to file_path (fixes issue #483).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user