mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix tests for context and permalinks
This commit is contained in:
@@ -27,7 +27,7 @@ class ContextResultRow:
|
||||
relation_type: Optional[str] = None
|
||||
category: Optional[str] = None
|
||||
entity_id: Optional[int] = None
|
||||
content: Optional[str] = None
|
||||
|
||||
|
||||
|
||||
class ContextService:
|
||||
@@ -50,8 +50,9 @@ class ContextService:
|
||||
async def build_context(
|
||||
self,
|
||||
memory_url: MemoryUrl,
|
||||
depth: int = 2,
|
||||
depth: int = 1,
|
||||
since: Optional[datetime] = None,
|
||||
max_results: int = 10
|
||||
):
|
||||
"""Build rich context from a memory:// URI."""
|
||||
logger.debug(f"Building context for URI {memory_url}")
|
||||
@@ -136,7 +137,6 @@ class ContextService:
|
||||
relation_type,
|
||||
category,
|
||||
entity_id,
|
||||
content,
|
||||
0 as depth,
|
||||
id as root_id,
|
||||
created_at
|
||||
@@ -157,7 +157,6 @@ class ContextService:
|
||||
related.relation_type,
|
||||
related.category,
|
||||
related.entity_id,
|
||||
related.content,
|
||||
cg.depth + 1,
|
||||
cg.root_id,
|
||||
related.created_at
|
||||
@@ -196,14 +195,13 @@ class ContextService:
|
||||
relation_type,
|
||||
category,
|
||||
entity_id,
|
||||
content,
|
||||
MIN(depth) as depth,
|
||||
root_id,
|
||||
created_at
|
||||
FROM context_graph
|
||||
GROUP BY
|
||||
type, id, title, permalink, from_id, to_id,
|
||||
relation_type, category, entity_id, content,
|
||||
relation_type, category, entity_id,
|
||||
root_id, created_at
|
||||
ORDER BY depth, type, id
|
||||
""")
|
||||
@@ -222,7 +220,6 @@ class ContextService:
|
||||
relation_type=row.relation_type,
|
||||
category=row.category,
|
||||
entity_id=row.entity_id,
|
||||
content=row.content,
|
||||
depth=row.depth,
|
||||
root_id=row.root_id,
|
||||
created_at=row.created_at,
|
||||
|
||||
@@ -5,9 +5,9 @@ from typing import Optional, Dict, Any, Tuple
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory import file_utils
|
||||
from basic_memory.markdown.knowledge_writer import KnowledgeWriter
|
||||
from basic_memory.services.exceptions import FileOperationError
|
||||
from basic_memory.utils import file_utils
|
||||
from basic_memory.models import Entity as EntityModel
|
||||
|
||||
|
||||
|
||||
@@ -4,15 +4,13 @@ from typing import Optional, Tuple, List
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.services.service import BaseService
|
||||
from basic_memory.repository.entity_repository import EntityRepository
|
||||
from basic_memory.services.search_service import SearchService
|
||||
from basic_memory.models import Entity
|
||||
from basic_memory.models.knowledge import generate_permalink
|
||||
from basic_memory.schemas.search import SearchQuery, SearchResult, SearchItemType
|
||||
|
||||
|
||||
class LinkResolver():
|
||||
class LinkResolver:
|
||||
"""Service for resolving markdown links to permalinks.
|
||||
|
||||
Uses a combination of exact matching and search-based resolution:
|
||||
@@ -31,8 +29,7 @@ class LinkResolver():
|
||||
self,
|
||||
link_text: str,
|
||||
) -> Entity:
|
||||
"""Resolve a markdown link to a permalink.
|
||||
"""
|
||||
"""Resolve a markdown link to a permalink."""
|
||||
logger.debug(f"Resolving link: {link_text}")
|
||||
|
||||
# Clean link text and extract any alias
|
||||
@@ -60,7 +57,6 @@ class LinkResolver():
|
||||
best_match = self._select_best_match(clean_text, results)
|
||||
logger.debug(f"Selected best match from {len(results)} results: {best_match.permalink}")
|
||||
return await self.entity_repository.get_by_permalink(best_match.permalink)
|
||||
|
||||
|
||||
def _normalize_link_text(self, link_text: str) -> Tuple[str, Optional[str]]:
|
||||
"""Normalize link text and extract alias if present.
|
||||
|
||||
Reference in New Issue
Block a user