mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
finish build_context
This commit is contained in:
@@ -64,16 +64,6 @@ class MemoryUrl(BaseModel):
|
||||
|
||||
# Create base URL
|
||||
url = cls(scheme=scheme, host=host, path=path)
|
||||
|
||||
# Parse special patterns
|
||||
path_no_slash = path[1:] if path.startswith("/") else path
|
||||
|
||||
# Extract special prefixes
|
||||
segments = path_no_slash.split("/")
|
||||
if segments and segments[0] in {"related", "context"}:
|
||||
url.params["type"] = segments[0]
|
||||
url.params["target"] = "/".join(segments[1:])
|
||||
|
||||
return url
|
||||
|
||||
@property
|
||||
|
||||
@@ -58,18 +58,9 @@ class ContextService:
|
||||
|
||||
# Parse the URI
|
||||
memory_url = MemoryUrl.parse(uri)
|
||||
|
||||
# Find primary entities based on URL type
|
||||
if memory_url.params.get("type") == "related":
|
||||
# Special mode for finding related content
|
||||
target = memory_url.params["target"]
|
||||
logger.debug(f"Finding related content for '{target}'")
|
||||
|
||||
# start by looking at direct relations
|
||||
primary = await self.find_related_1(target)
|
||||
|
||||
# Pattern matching - use search
|
||||
elif '*' in memory_url.relative_path():
|
||||
if '*' in memory_url.relative_path():
|
||||
logger.debug(f"Pattern search for '{memory_url.relative_path()}'")
|
||||
primary = await self.search_repository.search(permalink_match=memory_url.relative_path())
|
||||
|
||||
@@ -104,20 +95,6 @@ class ContextService:
|
||||
},
|
||||
}
|
||||
|
||||
async def find_related_1(self, permalink: str):
|
||||
"""Find entities related to a given permalink."""
|
||||
# First find the target entity
|
||||
target = await self.search_repository.search(permalink=permalink)
|
||||
if not target:
|
||||
return []
|
||||
|
||||
# Use find_connected to get related items at depth=1
|
||||
type_id_pairs = [(r.type, r.id) for r in target]
|
||||
return await self.find_connected(
|
||||
type_id_pairs,
|
||||
max_depth=1, # Only immediate relations
|
||||
)
|
||||
|
||||
async def find_connected(
|
||||
self,
|
||||
type_id_pairs: List[Tuple[str, int]],
|
||||
|
||||
Reference in New Issue
Block a user