mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
add get_observation_categories
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
from fastapi import APIRouter
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.deps import EntityServiceDep
|
||||
from basic_memory.deps import EntityServiceDep, ObservationServiceDep
|
||||
from basic_memory.schemas import EntityTypeList, ObservationCategoryList
|
||||
|
||||
router = APIRouter(prefix="/discovery", tags=["discovery"])
|
||||
@@ -15,3 +15,11 @@ async def get_entity_types(entity_service: EntityServiceDep) -> EntityTypeList:
|
||||
logger.debug("Getting all entity types")
|
||||
types = await entity_service.get_entity_types()
|
||||
return EntityTypeList(types=types)
|
||||
|
||||
|
||||
@router.get("/observation-categories", response_model=ObservationCategoryList)
|
||||
async def get_observation_categories(observation_service: ObservationServiceDep) -> ObservationCategoryList:
|
||||
"""Get list of all unique observation categories in the system."""
|
||||
logger.debug("Getting all observation categories")
|
||||
categories = await observation_service.observation_categories()
|
||||
return ObservationCategoryList(categories=categories)
|
||||
|
||||
@@ -11,8 +11,8 @@ from basic_memory.config import config
|
||||
from basic_memory.mcp.server import mcp
|
||||
|
||||
# Import tools to register them
|
||||
from basic_memory.mcp.tools import knowledge, search, documents
|
||||
__all__ = ["mcp", "knowledge", "search", "documents"]
|
||||
from basic_memory.mcp.tools import knowledge, search, documents, discovery
|
||||
__all__ = ["mcp", "knowledge", "search", "documents", "discovery"]
|
||||
|
||||
|
||||
def setup_logging(home_dir: str = config.home, log_file: str = "basic-memory.log"):
|
||||
|
||||
@@ -37,6 +37,7 @@ from basic_memory.mcp.tools.documents import (
|
||||
|
||||
from basic_memory.mcp.tools.discovery import (
|
||||
get_entity_types,
|
||||
get_observation_categories,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -62,4 +63,5 @@ __all__ = [
|
||||
|
||||
# Discovery tools
|
||||
"get_entity_types",
|
||||
"get_observation_categories",
|
||||
]
|
||||
@@ -4,7 +4,7 @@ from typing import List
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.schemas import EntityTypeList
|
||||
from basic_memory.schemas import EntityTypeList, ObservationCategoryList
|
||||
from basic_memory.mcp.async_client import client
|
||||
from basic_memory.mcp.server import mcp
|
||||
|
||||
@@ -30,4 +30,28 @@ async def get_entity_types() -> List[str]:
|
||||
logger.debug("Getting all entity types")
|
||||
url = "/discovery/entity-types"
|
||||
response = await client.get(url)
|
||||
return EntityTypeList.model_validate(response.json()).types
|
||||
return EntityTypeList.model_validate(response.json())
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
async def get_observation_categories() -> List[str]:
|
||||
"""List all unique observation categories in use across the knowledge graph.
|
||||
|
||||
Examples:
|
||||
categories = await get_observation_categories()
|
||||
|
||||
# Returns list of strings like:
|
||||
# [
|
||||
# "tech",
|
||||
# "design",
|
||||
# "feature",
|
||||
# "note"
|
||||
# ]
|
||||
|
||||
Returns:
|
||||
List of unique observation category strings used in the knowledge graph
|
||||
"""
|
||||
logger.debug("Getting all observation categories")
|
||||
url = "/discovery/observation-categories"
|
||||
response = await client.get(url)
|
||||
return ObservationCategoryList.model_validate(response.json())
|
||||
|
||||
@@ -36,5 +36,5 @@ class ObservationRepository(Repository[Observation]):
|
||||
async def observation_categories(self) -> Sequence[str]:
|
||||
"""Return a list of all observation categories."""
|
||||
query = select(Observation.category).distinct()
|
||||
result = await self.execute_query(query)
|
||||
result = await self.execute_query(query, use_query_options=False)
|
||||
return result.scalars().all()
|
||||
|
||||
Reference in New Issue
Block a user