hindsight-api 0.2.1__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hindsight_api/admin/__init__.py +1 -0
- hindsight_api/admin/cli.py +311 -0
- hindsight_api/alembic/versions/f1a2b3c4d5e6_add_memory_links_composite_index.py +44 -0
- hindsight_api/alembic/versions/g2a3b4c5d6e7_add_tags_column.py +48 -0
- hindsight_api/alembic/versions/h3c4d5e6f7g8_mental_models_v4.py +112 -0
- hindsight_api/alembic/versions/i4d5e6f7g8h9_delete_opinions.py +41 -0
- hindsight_api/alembic/versions/j5e6f7g8h9i0_mental_model_versions.py +95 -0
- hindsight_api/alembic/versions/k6f7g8h9i0j1_add_directive_subtype.py +58 -0
- hindsight_api/alembic/versions/l7g8h9i0j1k2_add_worker_columns.py +109 -0
- hindsight_api/alembic/versions/m8h9i0j1k2l3_mental_model_id_to_text.py +41 -0
- hindsight_api/alembic/versions/n9i0j1k2l3m4_learnings_and_pinned_reflections.py +134 -0
- hindsight_api/alembic/versions/o0j1k2l3m4n5_migrate_mental_models_data.py +113 -0
- hindsight_api/alembic/versions/p1k2l3m4n5o6_new_knowledge_architecture.py +194 -0
- hindsight_api/alembic/versions/q2l3m4n5o6p7_fix_mental_model_fact_type.py +50 -0
- hindsight_api/alembic/versions/r3m4n5o6p7q8_add_reflect_response_to_reflections.py +47 -0
- hindsight_api/alembic/versions/s4n5o6p7q8r9_add_consolidated_at_to_memory_units.py +53 -0
- hindsight_api/alembic/versions/t5o6p7q8r9s0_rename_mental_models_to_observations.py +134 -0
- hindsight_api/alembic/versions/u6p7q8r9s0t1_mental_models_text_id.py +41 -0
- hindsight_api/alembic/versions/v7q8r9s0t1u2_add_max_tokens_to_mental_models.py +50 -0
- hindsight_api/api/http.py +1406 -118
- hindsight_api/api/mcp.py +11 -196
- hindsight_api/config.py +359 -27
- hindsight_api/engine/consolidation/__init__.py +5 -0
- hindsight_api/engine/consolidation/consolidator.py +859 -0
- hindsight_api/engine/consolidation/prompts.py +69 -0
- hindsight_api/engine/cross_encoder.py +706 -88
- hindsight_api/engine/db_budget.py +284 -0
- hindsight_api/engine/db_utils.py +11 -0
- hindsight_api/engine/directives/__init__.py +5 -0
- hindsight_api/engine/directives/models.py +37 -0
- hindsight_api/engine/embeddings.py +553 -29
- hindsight_api/engine/entity_resolver.py +8 -5
- hindsight_api/engine/interface.py +40 -17
- hindsight_api/engine/llm_wrapper.py +744 -68
- hindsight_api/engine/memory_engine.py +2505 -1017
- hindsight_api/engine/mental_models/__init__.py +14 -0
- hindsight_api/engine/mental_models/models.py +53 -0
- hindsight_api/engine/query_analyzer.py +4 -3
- hindsight_api/engine/reflect/__init__.py +18 -0
- hindsight_api/engine/reflect/agent.py +933 -0
- hindsight_api/engine/reflect/models.py +109 -0
- hindsight_api/engine/reflect/observations.py +186 -0
- hindsight_api/engine/reflect/prompts.py +483 -0
- hindsight_api/engine/reflect/tools.py +437 -0
- hindsight_api/engine/reflect/tools_schema.py +250 -0
- hindsight_api/engine/response_models.py +168 -4
- hindsight_api/engine/retain/bank_utils.py +79 -201
- hindsight_api/engine/retain/fact_extraction.py +424 -195
- hindsight_api/engine/retain/fact_storage.py +35 -12
- hindsight_api/engine/retain/link_utils.py +29 -24
- hindsight_api/engine/retain/orchestrator.py +24 -43
- hindsight_api/engine/retain/types.py +11 -2
- hindsight_api/engine/search/graph_retrieval.py +43 -14
- hindsight_api/engine/search/link_expansion_retrieval.py +391 -0
- hindsight_api/engine/search/mpfp_retrieval.py +362 -117
- hindsight_api/engine/search/reranking.py +2 -2
- hindsight_api/engine/search/retrieval.py +848 -201
- hindsight_api/engine/search/tags.py +172 -0
- hindsight_api/engine/search/think_utils.py +42 -141
- hindsight_api/engine/search/trace.py +12 -1
- hindsight_api/engine/search/tracer.py +26 -6
- hindsight_api/engine/search/types.py +21 -3
- hindsight_api/engine/task_backend.py +113 -106
- hindsight_api/engine/utils.py +1 -152
- hindsight_api/extensions/__init__.py +10 -1
- hindsight_api/extensions/builtin/tenant.py +5 -1
- hindsight_api/extensions/context.py +10 -1
- hindsight_api/extensions/operation_validator.py +81 -4
- hindsight_api/extensions/tenant.py +26 -0
- hindsight_api/main.py +69 -6
- hindsight_api/mcp_local.py +12 -53
- hindsight_api/mcp_tools.py +494 -0
- hindsight_api/metrics.py +433 -48
- hindsight_api/migrations.py +141 -1
- hindsight_api/models.py +3 -3
- hindsight_api/pg0.py +53 -0
- hindsight_api/server.py +39 -2
- hindsight_api/worker/__init__.py +11 -0
- hindsight_api/worker/main.py +296 -0
- hindsight_api/worker/poller.py +486 -0
- {hindsight_api-0.2.1.dist-info → hindsight_api-0.4.0.dist-info}/METADATA +16 -6
- hindsight_api-0.4.0.dist-info/RECORD +112 -0
- {hindsight_api-0.2.1.dist-info → hindsight_api-0.4.0.dist-info}/entry_points.txt +2 -0
- hindsight_api/engine/retain/observation_regeneration.py +0 -254
- hindsight_api/engine/search/observation_utils.py +0 -125
- hindsight_api/engine/search/scoring.py +0 -159
- hindsight_api-0.2.1.dist-info/RECORD +0 -75
- {hindsight_api-0.2.1.dist-info → hindsight_api-0.4.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Prompts for the consolidation engine."""
|
|
2
|
+
|
|
3
|
+
CONSOLIDATION_SYSTEM_PROMPT = """You are a memory consolidation system. Your job is to convert facts into durable knowledge (observations) and merge with existing knowledge when appropriate.
|
|
4
|
+
|
|
5
|
+
You must output ONLY valid JSON with no markdown formatting, no code blocks, and no additional text.
|
|
6
|
+
|
|
7
|
+
## EXTRACT DURABLE KNOWLEDGE, NOT EPHEMERAL STATE
|
|
8
|
+
Facts often describe events or actions. Extract the DURABLE KNOWLEDGE implied by the fact, not the transient state.
|
|
9
|
+
|
|
10
|
+
Examples of extracting durable knowledge:
|
|
11
|
+
- "User moved to Room 203" -> "Room 203 exists" (location exists, not where user is now)
|
|
12
|
+
- "User visited Acme Corp at Room 105" -> "Acme Corp is located in Room 105"
|
|
13
|
+
- "User took the elevator to floor 3" -> "Floor 3 is accessible by elevator"
|
|
14
|
+
- "User met Sarah at the lobby" -> "Sarah can be found at the lobby"
|
|
15
|
+
|
|
16
|
+
DO NOT track current user position/state as knowledge - that changes constantly.
|
|
17
|
+
DO track permanent facts learned from the user's actions.
|
|
18
|
+
|
|
19
|
+
## PRESERVE SPECIFIC DETAILS
|
|
20
|
+
Keep names, locations, numbers, and other specifics. Do NOT:
|
|
21
|
+
- Abstract into general principles
|
|
22
|
+
- Generate business insights
|
|
23
|
+
- Make knowledge generic
|
|
24
|
+
|
|
25
|
+
GOOD examples:
|
|
26
|
+
- Fact: "John likes pizza" -> "John likes pizza"
|
|
27
|
+
- Fact: "Alice works at Google" -> "Alice works at Google"
|
|
28
|
+
|
|
29
|
+
BAD examples:
|
|
30
|
+
- "John likes pizza" -> "Understanding dietary preferences helps..." (TOO ABSTRACT)
|
|
31
|
+
- "User is at Room 203" -> "User is currently at Room 203" (EPHEMERAL STATE)
|
|
32
|
+
|
|
33
|
+
## MERGE RULES (when comparing to existing observations):
|
|
34
|
+
1. REDUNDANT: Same information worded differently → update existing
|
|
35
|
+
2. CONTRADICTION: Opposite information about same topic → update with history (e.g., "used to X, now Y")
|
|
36
|
+
3. UPDATE: New state replacing old state → update with history
|
|
37
|
+
|
|
38
|
+
## CRITICAL RULES:
|
|
39
|
+
- NEVER merge facts about DIFFERENT people
|
|
40
|
+
- NEVER merge unrelated topics (food preferences vs work vs hobbies)
|
|
41
|
+
- When merging contradictions, capture the CHANGE (before → after)
|
|
42
|
+
- Keep observations focused on ONE specific topic per person
|
|
43
|
+
- The "text" field MUST contain durable knowledge, not ephemeral state
|
|
44
|
+
- Do NOT include "tags" in output - tags are handled automatically"""
|
|
45
|
+
|
|
46
|
+
CONSOLIDATION_USER_PROMPT = """Analyze this new fact and consolidate into knowledge.
|
|
47
|
+
{mission_section}
|
|
48
|
+
NEW FACT: {fact_text}
|
|
49
|
+
|
|
50
|
+
EXISTING OBSERVATIONS:
|
|
51
|
+
{observations_text}
|
|
52
|
+
|
|
53
|
+
Instructions:
|
|
54
|
+
1. First, extract the DURABLE KNOWLEDGE from the fact (not ephemeral state like "user is at X")
|
|
55
|
+
2. Then compare with existing observations:
|
|
56
|
+
- If an observation covers the same topic: UPDATE it with the new knowledge
|
|
57
|
+
- If no observation covers the topic: CREATE a new one
|
|
58
|
+
|
|
59
|
+
Output JSON array of actions (ALWAYS an array, even for single action):
|
|
60
|
+
[
|
|
61
|
+
{{"action": "update", "learning_id": "uuid", "text": "updated durable knowledge", "reason": "..."}},
|
|
62
|
+
{{"action": "create", "text": "new durable knowledge", "reason": "..."}}
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
If NO consolidation is needed (fact is purely ephemeral with no durable knowledge):
|
|
66
|
+
[]
|
|
67
|
+
|
|
68
|
+
If no observations exist and fact contains durable knowledge:
|
|
69
|
+
[{{"action": "create", "text": "durable knowledge text", "reason": "new topic"}}]"""
|