hindsight-api 0.0.13__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 (48) hide show
  1. hindsight_api/__init__.py +38 -0
  2. hindsight_api/api/__init__.py +105 -0
  3. hindsight_api/api/http.py +1872 -0
  4. hindsight_api/api/mcp.py +157 -0
  5. hindsight_api/engine/__init__.py +47 -0
  6. hindsight_api/engine/cross_encoder.py +97 -0
  7. hindsight_api/engine/db_utils.py +93 -0
  8. hindsight_api/engine/embeddings.py +113 -0
  9. hindsight_api/engine/entity_resolver.py +575 -0
  10. hindsight_api/engine/llm_wrapper.py +269 -0
  11. hindsight_api/engine/memory_engine.py +3095 -0
  12. hindsight_api/engine/query_analyzer.py +519 -0
  13. hindsight_api/engine/response_models.py +222 -0
  14. hindsight_api/engine/retain/__init__.py +50 -0
  15. hindsight_api/engine/retain/bank_utils.py +423 -0
  16. hindsight_api/engine/retain/chunk_storage.py +82 -0
  17. hindsight_api/engine/retain/deduplication.py +104 -0
  18. hindsight_api/engine/retain/embedding_processing.py +62 -0
  19. hindsight_api/engine/retain/embedding_utils.py +54 -0
  20. hindsight_api/engine/retain/entity_processing.py +90 -0
  21. hindsight_api/engine/retain/fact_extraction.py +1027 -0
  22. hindsight_api/engine/retain/fact_storage.py +176 -0
  23. hindsight_api/engine/retain/link_creation.py +121 -0
  24. hindsight_api/engine/retain/link_utils.py +651 -0
  25. hindsight_api/engine/retain/orchestrator.py +405 -0
  26. hindsight_api/engine/retain/types.py +206 -0
  27. hindsight_api/engine/search/__init__.py +15 -0
  28. hindsight_api/engine/search/fusion.py +122 -0
  29. hindsight_api/engine/search/observation_utils.py +132 -0
  30. hindsight_api/engine/search/reranking.py +103 -0
  31. hindsight_api/engine/search/retrieval.py +503 -0
  32. hindsight_api/engine/search/scoring.py +161 -0
  33. hindsight_api/engine/search/temporal_extraction.py +64 -0
  34. hindsight_api/engine/search/think_utils.py +255 -0
  35. hindsight_api/engine/search/trace.py +215 -0
  36. hindsight_api/engine/search/tracer.py +447 -0
  37. hindsight_api/engine/search/types.py +160 -0
  38. hindsight_api/engine/task_backend.py +223 -0
  39. hindsight_api/engine/utils.py +203 -0
  40. hindsight_api/metrics.py +227 -0
  41. hindsight_api/migrations.py +163 -0
  42. hindsight_api/models.py +309 -0
  43. hindsight_api/pg0.py +425 -0
  44. hindsight_api/web/__init__.py +12 -0
  45. hindsight_api/web/server.py +143 -0
  46. hindsight_api-0.0.13.dist-info/METADATA +41 -0
  47. hindsight_api-0.0.13.dist-info/RECORD +48 -0
  48. hindsight_api-0.0.13.dist-info/WHEEL +4 -0
@@ -0,0 +1,38 @@
1
+ """
2
+ Memory System for AI Agents.
3
+
4
+ Temporal + Semantic Memory Architecture using PostgreSQL with pgvector.
5
+ """
6
+ from .engine.memory_engine import MemoryEngine
7
+ from .engine.search.trace import (
8
+ SearchTrace,
9
+ QueryInfo,
10
+ EntryPoint,
11
+ NodeVisit,
12
+ WeightComponents,
13
+ LinkInfo,
14
+ PruningDecision,
15
+ SearchSummary,
16
+ SearchPhaseMetrics,
17
+ )
18
+ from .engine.search.tracer import SearchTracer
19
+ from .engine.embeddings import Embeddings, SentenceTransformersEmbeddings
20
+ from .engine.llm_wrapper import LLMConfig
21
+
22
+ __all__ = [
23
+ "MemoryEngine",
24
+ "SearchTrace",
25
+ "SearchTracer",
26
+ "QueryInfo",
27
+ "EntryPoint",
28
+ "NodeVisit",
29
+ "WeightComponents",
30
+ "LinkInfo",
31
+ "PruningDecision",
32
+ "SearchSummary",
33
+ "SearchPhaseMetrics",
34
+ "Embeddings",
35
+ "SentenceTransformersEmbeddings",
36
+ "LLMConfig",
37
+ ]
38
+ __version__ = "0.1.0"
@@ -0,0 +1,105 @@
1
+ """
2
+ Unified API module for Hindsight.
3
+
4
+ Provides both HTTP REST API and MCP (Model Context Protocol) server.
5
+ """
6
+ import logging
7
+ from typing import Optional
8
+ from fastapi import FastAPI
9
+
10
+ from hindsight_api import MemoryEngine
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+
15
+ def create_app(
16
+ memory: MemoryEngine,
17
+ http_api_enabled: bool = True,
18
+ mcp_api_enabled: bool = False,
19
+ mcp_mount_path: str = "/mcp",
20
+ run_migrations: bool = True,
21
+ initialize_memory: bool = True
22
+ ) -> FastAPI:
23
+ """
24
+ Create and configure the unified Hindsight API application.
25
+
26
+ Args:
27
+ memory: MemoryEngine instance (already initialized with required parameters)
28
+ http_api_enabled: Whether to enable HTTP REST API endpoints (default: True)
29
+ mcp_api_enabled: Whether to enable MCP server (default: False)
30
+ mcp_mount_path: Path to mount MCP server (default: /mcp)
31
+ run_migrations: Whether to run database migrations on startup (default: True)
32
+ initialize_memory: Whether to initialize memory system on startup (default: True)
33
+
34
+ Returns:
35
+ Configured FastAPI application with enabled APIs
36
+
37
+ Example:
38
+ # HTTP only
39
+ app = create_app(memory)
40
+
41
+ # MCP only
42
+ app = create_app(memory, http_api_enabled=False, mcp_api_enabled=True)
43
+
44
+ # Both HTTP and MCP
45
+ app = create_app(memory, mcp_api_enabled=True)
46
+ """
47
+
48
+ # Import and create HTTP API if enabled
49
+ if http_api_enabled:
50
+ from .http import create_app as create_http_app
51
+ app = create_http_app(
52
+ memory=memory,
53
+ run_migrations=run_migrations,
54
+ initialize_memory=initialize_memory
55
+ )
56
+ logger.info("HTTP REST API enabled")
57
+ else:
58
+ # Create minimal FastAPI app
59
+ app = FastAPI(title="Hindsight API", version="0.0.7")
60
+ logger.info("HTTP REST API disabled")
61
+
62
+ # Mount MCP server if enabled
63
+ if mcp_api_enabled:
64
+ try:
65
+ from .mcp import create_mcp_server
66
+
67
+ # Create MCP server with shared memory instance
68
+ mcp_server = create_mcp_server(memory=memory)
69
+
70
+ # Mount at specified path using http_app (modern non-SSE alternative)
71
+ app.mount(mcp_mount_path, mcp_server.http_app())
72
+ logger.info(f"MCP server enabled at {mcp_mount_path}")
73
+ except ImportError as e:
74
+ logger.error(f"MCP server requested but dependencies not available: {e}")
75
+ logger.error("Install with: pip install hindsight-api[mcp]")
76
+ raise
77
+
78
+ return app
79
+
80
+
81
+ # Re-export commonly used items for backwards compatibility
82
+ from .http import (
83
+ RecallRequest,
84
+ RecallResult,
85
+ RecallResponse,
86
+ MemoryItem,
87
+ RetainRequest,
88
+ ReflectRequest,
89
+ ReflectResponse,
90
+ CreateBankRequest,
91
+ PersonalityTraits,
92
+ )
93
+
94
+ __all__ = [
95
+ "create_app",
96
+ "RecallRequest",
97
+ "RecallResult",
98
+ "RecallResponse",
99
+ "MemoryItem",
100
+ "RetainRequest",
101
+ "ReflectRequest",
102
+ "ReflectResponse",
103
+ "CreateBankRequest",
104
+ "PersonalityTraits",
105
+ ]