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
42 changes: 42 additions & 0 deletions hindsight-api/hindsight_api/api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,14 @@ class DeleteResponse(BaseModel):
deleted_count: int | None = None


class ClearMemoryObservationsResponse(BaseModel):
"""Response model for clearing observations for a specific memory."""

model_config = ConfigDict(json_schema_extra={"example": {"deleted_count": 3}})

deleted_count: int


class BankStatsResponse(BaseModel):
"""Response model for bank statistics endpoint."""

Expand Down Expand Up @@ -3549,6 +3557,40 @@ async def api_clear_observations(bank_id: str, request_context: RequestContext =
logger.error(f"Error in DELETE /v1/default/banks/{bank_id}/observations: {error_detail}")
raise HTTPException(status_code=500, detail=str(e))

@app.delete(
"/v1/default/banks/{bank_id}/memories/{memory_id}/observations",
response_model=ClearMemoryObservationsResponse,
summary="Clear observations for a memory",
description="Delete all observations derived from a specific memory and reset it for re-consolidation. "
"The memory itself is not deleted. A consolidation job is triggered automatically so the memory "
"will produce fresh observations on the next consolidation run.",
operation_id="clear_memory_observations",
tags=["Memory"],
)
async def api_clear_memory_observations(
bank_id: str,
memory_id: str,
request_context: RequestContext = Depends(get_request_context),
):
"""Clear all observations derived from a specific memory."""
try:
result = await app.state.memory.clear_observations_for_memory(
bank_id=bank_id,
memory_id=memory_id,
request_context=request_context,
)
return ClearMemoryObservationsResponse(deleted_count=result["deleted_count"])
except (AuthenticationError, HTTPException):
raise
except Exception as e:
import traceback

error_detail = f"{str(e)}\n\nTraceback:\n{traceback.format_exc()}"
logger.error(
f"Error in DELETE /v1/default/banks/{bank_id}/memories/{memory_id}/observations: {error_detail}"
)
raise HTTPException(status_code=500, detail=str(e))

@app.get(
"/v1/default/banks/{bank_id}/config",
response_model=BankConfigResponse,
Expand Down
3 changes: 2 additions & 1 deletion hindsight-api/hindsight_api/engine/consolidation/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
- Keep specifics: names, numbers, locations. Never abstract into general principles.
- NEVER merge observations about different people or unrelated topics.
- REDUNDANT: same info worded differently → update existing.
- CONTRADICTION/UPDATE: capture both states with temporal markers ("used to X, now Y")."""
- CONTRADICTION/UPDATE: capture both states with temporal markers ("used to X, now Y").
- RESOLVE REFERENCES: When a new fact provides a concrete value that resolves a vague placeholder in an existing observation (e.g., a location that corresponds to "home country", "hometown", "birthplace", "native language", "her ex", "that city"), UPDATE the existing observation to embed the resolved value explicitly. Example: new fact mentions grandma in Sweden + existing observation says "moved from her home country" → update to state "home country is Sweden"."""


def build_consolidation_prompt(observations_mission: str | None = None) -> str:
Expand Down
Loading
Loading