hindsight-api 0.1.5__py3-none-any.whl → 0.1.7__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.
Files changed (64) hide show
  1. hindsight_api/__init__.py +10 -9
  2. hindsight_api/alembic/env.py +5 -8
  3. hindsight_api/alembic/versions/5a366d414dce_initial_schema.py +266 -180
  4. hindsight_api/alembic/versions/b7c4d8e9f1a2_add_chunks_table.py +32 -32
  5. hindsight_api/alembic/versions/c8e5f2a3b4d1_add_retain_params_to_documents.py +11 -11
  6. hindsight_api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py +7 -12
  7. hindsight_api/alembic/versions/e0a1b2c3d4e5_disposition_to_3_traits.py +23 -15
  8. hindsight_api/alembic/versions/rename_personality_to_disposition.py +30 -21
  9. hindsight_api/api/__init__.py +10 -10
  10. hindsight_api/api/http.py +575 -593
  11. hindsight_api/api/mcp.py +30 -28
  12. hindsight_api/banner.py +13 -6
  13. hindsight_api/config.py +9 -13
  14. hindsight_api/engine/__init__.py +9 -9
  15. hindsight_api/engine/cross_encoder.py +22 -21
  16. hindsight_api/engine/db_utils.py +5 -4
  17. hindsight_api/engine/embeddings.py +22 -21
  18. hindsight_api/engine/entity_resolver.py +81 -75
  19. hindsight_api/engine/llm_wrapper.py +61 -79
  20. hindsight_api/engine/memory_engine.py +603 -625
  21. hindsight_api/engine/query_analyzer.py +100 -97
  22. hindsight_api/engine/response_models.py +105 -106
  23. hindsight_api/engine/retain/__init__.py +9 -16
  24. hindsight_api/engine/retain/bank_utils.py +34 -58
  25. hindsight_api/engine/retain/chunk_storage.py +4 -12
  26. hindsight_api/engine/retain/deduplication.py +9 -28
  27. hindsight_api/engine/retain/embedding_processing.py +4 -11
  28. hindsight_api/engine/retain/embedding_utils.py +3 -4
  29. hindsight_api/engine/retain/entity_processing.py +7 -17
  30. hindsight_api/engine/retain/fact_extraction.py +155 -165
  31. hindsight_api/engine/retain/fact_storage.py +11 -23
  32. hindsight_api/engine/retain/link_creation.py +11 -39
  33. hindsight_api/engine/retain/link_utils.py +166 -95
  34. hindsight_api/engine/retain/observation_regeneration.py +39 -52
  35. hindsight_api/engine/retain/orchestrator.py +72 -62
  36. hindsight_api/engine/retain/types.py +49 -43
  37. hindsight_api/engine/search/__init__.py +5 -5
  38. hindsight_api/engine/search/fusion.py +6 -15
  39. hindsight_api/engine/search/graph_retrieval.py +22 -23
  40. hindsight_api/engine/search/mpfp_retrieval.py +76 -92
  41. hindsight_api/engine/search/observation_utils.py +9 -16
  42. hindsight_api/engine/search/reranking.py +4 -7
  43. hindsight_api/engine/search/retrieval.py +87 -66
  44. hindsight_api/engine/search/scoring.py +5 -7
  45. hindsight_api/engine/search/temporal_extraction.py +8 -11
  46. hindsight_api/engine/search/think_utils.py +115 -39
  47. hindsight_api/engine/search/trace.py +68 -39
  48. hindsight_api/engine/search/tracer.py +44 -35
  49. hindsight_api/engine/search/types.py +20 -17
  50. hindsight_api/engine/task_backend.py +21 -26
  51. hindsight_api/engine/utils.py +25 -10
  52. hindsight_api/main.py +21 -40
  53. hindsight_api/mcp_local.py +190 -0
  54. hindsight_api/metrics.py +44 -30
  55. hindsight_api/migrations.py +10 -8
  56. hindsight_api/models.py +60 -72
  57. hindsight_api/pg0.py +22 -23
  58. hindsight_api/server.py +3 -6
  59. hindsight_api-0.1.7.dist-info/METADATA +178 -0
  60. hindsight_api-0.1.7.dist-info/RECORD +64 -0
  61. {hindsight_api-0.1.5.dist-info → hindsight_api-0.1.7.dist-info}/entry_points.txt +1 -0
  62. hindsight_api-0.1.5.dist-info/METADATA +0 -42
  63. hindsight_api-0.1.5.dist-info/RECORD +0 -63
  64. {hindsight_api-0.1.5.dist-info → hindsight_api-0.1.7.dist-info}/WHEEL +0 -0
@@ -3,9 +3,8 @@ Embedding processing for retain pipeline.
3
3
 
4
4
  Handles augmenting fact texts with temporal information and generating embeddings.
5
5
  """
6
+
6
7
  import logging
7
- from typing import List
8
- from datetime import datetime
9
8
 
10
9
  from . import embedding_utils
11
10
  from .types import ExtractedFact
@@ -13,7 +12,7 @@ from .types import ExtractedFact
13
12
  logger = logging.getLogger(__name__)
14
13
 
15
14
 
16
- def augment_texts_with_dates(facts: List[ExtractedFact], format_date_fn) -> List[str]:
15
+ def augment_texts_with_dates(facts: list[ExtractedFact], format_date_fn) -> list[str]:
17
16
  """
18
17
  Augment fact texts with readable dates for better temporal matching.
19
18
 
@@ -37,10 +36,7 @@ def augment_texts_with_dates(facts: List[ExtractedFact], format_date_fn) -> List
37
36
  return augmented_texts
38
37
 
39
38
 
40
- async def generate_embeddings_batch(
41
- embeddings_model,
42
- texts: List[str]
43
- ) -> List[List[float]]:
39
+ async def generate_embeddings_batch(embeddings_model, texts: list[str]) -> list[list[float]]:
44
40
  """
45
41
  Generate embeddings for a batch of texts.
46
42
 
@@ -54,9 +50,6 @@ async def generate_embeddings_batch(
54
50
  if not texts:
55
51
  return []
56
52
 
57
- embeddings = await embedding_utils.generate_embeddings_batch(
58
- embeddings_model,
59
- texts
60
- )
53
+ embeddings = await embedding_utils.generate_embeddings_batch(embeddings_model, texts)
61
54
 
62
55
  return embeddings
@@ -4,12 +4,11 @@ Embedding generation utilities for memory units.
4
4
 
5
5
  import asyncio
6
6
  import logging
7
- from typing import List
8
7
 
9
8
  logger = logging.getLogger(__name__)
10
9
 
11
10
 
12
- def generate_embedding(embeddings_backend, text: str) -> List[float]:
11
+ def generate_embedding(embeddings_backend, text: str) -> list[float]:
13
12
  """
14
13
  Generate embedding for text using the provided embeddings backend.
15
14
 
@@ -27,7 +26,7 @@ def generate_embedding(embeddings_backend, text: str) -> List[float]:
27
26
  raise Exception(f"Failed to generate embedding: {str(e)}")
28
27
 
29
28
 
30
- async def generate_embeddings_batch(embeddings_backend, texts: List[str]) -> List[List[float]]:
29
+ async def generate_embeddings_batch(embeddings_backend, texts: list[str]) -> list[list[float]]:
31
30
  """
32
31
  Generate embeddings for multiple texts using the provided embeddings backend.
33
32
 
@@ -47,7 +46,7 @@ async def generate_embeddings_batch(embeddings_backend, texts: List[str]) -> Lis
47
46
  embeddings = await loop.run_in_executor(
48
47
  None, # Use default thread pool
49
48
  embeddings_backend.encode,
50
- texts
49
+ texts,
51
50
  )
52
51
  return embeddings
53
52
  except Exception as e:
@@ -3,24 +3,18 @@ Entity processing for retain pipeline.
3
3
 
4
4
  Handles entity extraction, resolution, and link creation for stored facts.
5
5
  """
6
+
6
7
  import logging
7
- from typing import List, Tuple, Dict, Any
8
- from uuid import UUID
9
8
 
10
- from .types import ProcessedFact, EntityRef, EntityLink
11
9
  from . import link_utils
10
+ from .types import EntityLink, ProcessedFact
12
11
 
13
12
  logger = logging.getLogger(__name__)
14
13
 
15
14
 
16
15
  async def process_entities_batch(
17
- entity_resolver,
18
- conn,
19
- bank_id: str,
20
- unit_ids: List[str],
21
- facts: List[ProcessedFact],
22
- log_buffer: List[str] = None
23
- ) -> List[EntityLink]:
16
+ entity_resolver, conn, bank_id: str, unit_ids: list[str], facts: list[ProcessedFact], log_buffer: list[str] = None
17
+ ) -> list[EntityLink]:
24
18
  """
25
19
  Process entities for all facts and create entity links.
26
20
 
@@ -53,8 +47,7 @@ async def process_entities_batch(
53
47
  fact_dates = [fact.occurred_start if fact.occurred_start is not None else fact.mentioned_at for fact in facts]
54
48
  # Convert EntityRef objects to dict format expected by link_utils
55
49
  entities_per_fact = [
56
- [{'text': entity.name, 'type': 'CONCEPT'} for entity in (fact.entities or [])]
57
- for fact in facts
50
+ [{"text": entity.name, "type": "CONCEPT"} for entity in (fact.entities or [])] for fact in facts
58
51
  ]
59
52
 
60
53
  # Use existing link_utils function for entity processing
@@ -67,16 +60,13 @@ async def process_entities_batch(
67
60
  "", # context (not used in current implementation)
68
61
  fact_dates,
69
62
  entities_per_fact,
70
- log_buffer # Pass log_buffer for detailed logging
63
+ log_buffer, # Pass log_buffer for detailed logging
71
64
  )
72
65
 
73
66
  return entity_links
74
67
 
75
68
 
76
- async def insert_entity_links_batch(
77
- conn,
78
- entity_links: List[EntityLink]
79
- ) -> None:
69
+ async def insert_entity_links_batch(conn, entity_links: list[EntityLink]) -> None:
80
70
  """
81
71
  Insert entity links in batch.
82
72