hindsight-api 0.1.0__py3-none-any.whl → 0.1.1__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/__init__.py +10 -2
- hindsight_api/alembic/README +1 -0
- hindsight_api/alembic/env.py +146 -0
- hindsight_api/alembic/script.py.mako +28 -0
- hindsight_api/alembic/versions/5a366d414dce_initial_schema.py +274 -0
- hindsight_api/alembic/versions/b7c4d8e9f1a2_add_chunks_table.py +70 -0
- hindsight_api/alembic/versions/c8e5f2a3b4d1_add_retain_params_to_documents.py +39 -0
- hindsight_api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py +48 -0
- hindsight_api/alembic/versions/e0a1b2c3d4e5_disposition_to_3_traits.py +62 -0
- hindsight_api/alembic/versions/rename_personality_to_disposition.py +65 -0
- hindsight_api/api/http.py +84 -86
- hindsight_api/config.py +154 -0
- hindsight_api/engine/__init__.py +7 -2
- hindsight_api/engine/cross_encoder.py +219 -15
- hindsight_api/engine/embeddings.py +192 -18
- hindsight_api/engine/llm_wrapper.py +88 -139
- hindsight_api/engine/memory_engine.py +71 -51
- hindsight_api/engine/retain/bank_utils.py +2 -2
- hindsight_api/engine/retain/fact_extraction.py +1 -1
- hindsight_api/engine/search/reranking.py +6 -10
- hindsight_api/engine/search/tracer.py +1 -1
- hindsight_api/main.py +201 -0
- hindsight_api/migrations.py +7 -7
- hindsight_api/server.py +43 -0
- {hindsight_api-0.1.0.dist-info → hindsight_api-0.1.1.dist-info}/METADATA +1 -1
- {hindsight_api-0.1.0.dist-info → hindsight_api-0.1.1.dist-info}/RECORD +28 -19
- hindsight_api-0.1.1.dist-info/entry_points.txt +2 -0
- hindsight_api/cli.py +0 -127
- hindsight_api/web/__init__.py +0 -12
- hindsight_api/web/server.py +0 -109
- hindsight_api-0.1.0.dist-info/entry_points.txt +0 -2
- {hindsight_api-0.1.0.dist-info → hindsight_api-0.1.1.dist-info}/WHEEL +0 -0
hindsight_api/cli.py
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Command-line interface for Hindsight API.
|
|
3
|
-
|
|
4
|
-
Run the server with:
|
|
5
|
-
hindsight-api
|
|
6
|
-
|
|
7
|
-
Stop with Ctrl+C.
|
|
8
|
-
"""
|
|
9
|
-
import argparse
|
|
10
|
-
import asyncio
|
|
11
|
-
import atexit
|
|
12
|
-
import os
|
|
13
|
-
import signal
|
|
14
|
-
import sys
|
|
15
|
-
from typing import Optional
|
|
16
|
-
|
|
17
|
-
import uvicorn
|
|
18
|
-
|
|
19
|
-
from . import MemoryEngine
|
|
20
|
-
from .api import create_app
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# Disable tokenizers parallelism to avoid warnings
|
|
24
|
-
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
25
|
-
|
|
26
|
-
# Global reference for cleanup
|
|
27
|
-
_memory: Optional[MemoryEngine] = None
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def _cleanup():
|
|
31
|
-
"""Synchronous cleanup function to stop resources on exit."""
|
|
32
|
-
global _memory
|
|
33
|
-
if _memory is not None and _memory._pg0 is not None:
|
|
34
|
-
try:
|
|
35
|
-
loop = asyncio.new_event_loop()
|
|
36
|
-
loop.run_until_complete(_memory._pg0.stop())
|
|
37
|
-
loop.close()
|
|
38
|
-
print("\npg0 stopped.")
|
|
39
|
-
except Exception as e:
|
|
40
|
-
print(f"\nError stopping pg0: {e}")
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def _signal_handler(signum, frame):
|
|
44
|
-
"""Handle SIGINT/SIGTERM to ensure cleanup."""
|
|
45
|
-
print(f"\nReceived signal {signum}, shutting down...")
|
|
46
|
-
_cleanup()
|
|
47
|
-
sys.exit(0)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def main():
|
|
51
|
-
"""Main entry point for the CLI."""
|
|
52
|
-
global _memory
|
|
53
|
-
|
|
54
|
-
parser = argparse.ArgumentParser(
|
|
55
|
-
prog="hindsight-api",
|
|
56
|
-
description="Hindsight API Server",
|
|
57
|
-
)
|
|
58
|
-
parser.add_argument(
|
|
59
|
-
"--host", default="0.0.0.0",
|
|
60
|
-
help="Host to bind to (default: 0.0.0.0)"
|
|
61
|
-
)
|
|
62
|
-
parser.add_argument(
|
|
63
|
-
"--port", type=int, default=8888,
|
|
64
|
-
help="Port to bind to (default: 8888)"
|
|
65
|
-
)
|
|
66
|
-
parser.add_argument(
|
|
67
|
-
"--log-level", default="info",
|
|
68
|
-
choices=["critical", "error", "warning", "info", "debug", "trace"],
|
|
69
|
-
help="Log level (default: info)"
|
|
70
|
-
)
|
|
71
|
-
parser.add_argument(
|
|
72
|
-
"--access-log", action="store_true",
|
|
73
|
-
help="Enable access log"
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
args = parser.parse_args()
|
|
77
|
-
|
|
78
|
-
# Register cleanup handlers
|
|
79
|
-
atexit.register(_cleanup)
|
|
80
|
-
signal.signal(signal.SIGINT, _signal_handler)
|
|
81
|
-
signal.signal(signal.SIGTERM, _signal_handler)
|
|
82
|
-
|
|
83
|
-
# Get configuration from environment variables
|
|
84
|
-
db_url = os.getenv("HINDSIGHT_API_DATABASE_URL", "pg0")
|
|
85
|
-
llm_provider = os.getenv("HINDSIGHT_API_LLM_PROVIDER", "groq")
|
|
86
|
-
llm_api_key = os.getenv("HINDSIGHT_API_LLM_API_KEY", "")
|
|
87
|
-
llm_model = os.getenv("HINDSIGHT_API_LLM_MODEL", "openai/gpt-oss-20b")
|
|
88
|
-
llm_base_url = os.getenv("HINDSIGHT_API_LLM_BASE_URL") or None
|
|
89
|
-
|
|
90
|
-
# Create MemoryEngine
|
|
91
|
-
_memory = MemoryEngine(
|
|
92
|
-
db_url=db_url,
|
|
93
|
-
memory_llm_provider=llm_provider,
|
|
94
|
-
memory_llm_api_key=llm_api_key,
|
|
95
|
-
memory_llm_model=llm_model,
|
|
96
|
-
memory_llm_base_url=llm_base_url,
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
# Create FastAPI app
|
|
100
|
-
app = create_app(
|
|
101
|
-
memory=_memory,
|
|
102
|
-
http_api_enabled=True,
|
|
103
|
-
mcp_api_enabled=True,
|
|
104
|
-
mcp_mount_path="/mcp",
|
|
105
|
-
initialize_memory=True,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
# Prepare uvicorn config
|
|
109
|
-
uvicorn_config = {
|
|
110
|
-
"app": app,
|
|
111
|
-
"host": args.host,
|
|
112
|
-
"port": args.port,
|
|
113
|
-
"log_level": args.log_level,
|
|
114
|
-
"access_log": args.access_log,
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
print(f"\nStarting Hindsight API...")
|
|
118
|
-
print(f" URL: http://{args.host}:{args.port}")
|
|
119
|
-
print(f" Database: {db_url}")
|
|
120
|
-
print(f" LLM Provider: {llm_provider}")
|
|
121
|
-
print()
|
|
122
|
-
|
|
123
|
-
uvicorn.run(**uvicorn_config)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if __name__ == "__main__":
|
|
127
|
-
main()
|
hindsight_api/web/__init__.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Web interface for memory system.
|
|
3
|
-
|
|
4
|
-
Provides FastAPI app and visualization interface.
|
|
5
|
-
"""
|
|
6
|
-
from hindsight_api.api import create_app
|
|
7
|
-
|
|
8
|
-
# Note: Don't import app from .server here to avoid circular import warnings
|
|
9
|
-
# when running with `python -m hindsight_api.web.server`
|
|
10
|
-
# If you need the app, import it directly: from hindsight_api.web.server import app
|
|
11
|
-
|
|
12
|
-
__all__ = ["create_app"]
|
hindsight_api/web/server.py
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FastAPI server for memory graph visualization and API.
|
|
3
|
-
|
|
4
|
-
Provides REST API endpoints for memory operations and serves
|
|
5
|
-
the interactive visualization interface.
|
|
6
|
-
"""
|
|
7
|
-
import warnings
|
|
8
|
-
|
|
9
|
-
# Filter deprecation warnings from third-party libraries
|
|
10
|
-
warnings.filterwarnings("ignore", message="websockets.legacy is deprecated")
|
|
11
|
-
warnings.filterwarnings("ignore", message="websockets.server.WebSocketServerProtocol is deprecated")
|
|
12
|
-
|
|
13
|
-
import logging
|
|
14
|
-
import os
|
|
15
|
-
import argparse
|
|
16
|
-
|
|
17
|
-
from hindsight_api import MemoryEngine
|
|
18
|
-
from hindsight_api.api import create_app
|
|
19
|
-
|
|
20
|
-
# Disable tokenizers parallelism to avoid warnings
|
|
21
|
-
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# Create app at module level (required for uvicorn import string)
|
|
25
|
-
_memory = MemoryEngine(
|
|
26
|
-
db_url=os.getenv("HINDSIGHT_API_DATABASE_URL", "pg0"),
|
|
27
|
-
memory_llm_provider=os.getenv("HINDSIGHT_API_LLM_PROVIDER", "groq"),
|
|
28
|
-
memory_llm_api_key=os.getenv("HINDSIGHT_API_LLM_API_KEY"),
|
|
29
|
-
memory_llm_model=os.getenv("HINDSIGHT_API_LLM_MODEL", "openai/gpt-oss-120b"),
|
|
30
|
-
memory_llm_base_url=os.getenv("HINDSIGHT_API_LLM_BASE_URL") or None,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
# Check if MCP should be enabled
|
|
34
|
-
mcp_enabled = os.getenv("HINDSIGHT_API_MCP_ENABLED", "true").lower() == "true"
|
|
35
|
-
|
|
36
|
-
# Create unified app with both HTTP and optionally MCP
|
|
37
|
-
app = create_app(
|
|
38
|
-
memory=_memory,
|
|
39
|
-
http_api_enabled=True,
|
|
40
|
-
mcp_api_enabled=mcp_enabled,
|
|
41
|
-
mcp_mount_path="/mcp"
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if __name__ == "__main__":
|
|
46
|
-
import uvicorn
|
|
47
|
-
|
|
48
|
-
# Get log level from environment variable (default: info)
|
|
49
|
-
env_log_level = os.environ.get("HINDSIGHT_API_LOG_LEVEL", "info").lower()
|
|
50
|
-
if env_log_level not in ["critical", "error", "warning", "info", "debug", "trace"]:
|
|
51
|
-
env_log_level = "info"
|
|
52
|
-
|
|
53
|
-
# Parse CLI arguments
|
|
54
|
-
parser = argparse.ArgumentParser(description="Hindsight API Server")
|
|
55
|
-
parser.add_argument("--host", default="0.0.0.0", help="Host to bind to (default: 0.0.0.0)")
|
|
56
|
-
parser.add_argument("--port", type=int, default=8888, help="Port to bind to (default: 8888)")
|
|
57
|
-
parser.add_argument("--reload", action="store_true", help="Enable auto-reload on code changes")
|
|
58
|
-
parser.add_argument("--workers", type=int, default=1, help="Number of worker processes (default: 1)")
|
|
59
|
-
parser.add_argument("--log-level", default=env_log_level, choices=["critical", "error", "warning", "info", "debug", "trace"],
|
|
60
|
-
help=f"Log level (default: {env_log_level}, from HINDSIGHT_API_LOG_LEVEL)")
|
|
61
|
-
parser.add_argument("--access-log", action="store_true", help="Enable access log")
|
|
62
|
-
parser.add_argument("--no-access-log", dest="access_log", action="store_false", help="Disable access log")
|
|
63
|
-
parser.add_argument("--proxy-headers", action="store_true", help="Enable X-Forwarded-Proto, X-Forwarded-For headers")
|
|
64
|
-
parser.add_argument("--forwarded-allow-ips", default=None, help="Comma separated list of IPs to trust with proxy headers")
|
|
65
|
-
parser.add_argument("--ssl-keyfile", default=None, help="SSL key file")
|
|
66
|
-
parser.add_argument("--ssl-certfile", default=None, help="SSL certificate file")
|
|
67
|
-
parser.set_defaults(access_log=False)
|
|
68
|
-
|
|
69
|
-
args = parser.parse_args()
|
|
70
|
-
|
|
71
|
-
# Configure Python logging based on log level
|
|
72
|
-
log_level_map = {
|
|
73
|
-
"critical": logging.CRITICAL,
|
|
74
|
-
"error": logging.ERROR,
|
|
75
|
-
"warning": logging.WARNING,
|
|
76
|
-
"info": logging.INFO,
|
|
77
|
-
"debug": logging.DEBUG,
|
|
78
|
-
"trace": logging.DEBUG, # Python doesn't have TRACE, use DEBUG
|
|
79
|
-
}
|
|
80
|
-
logging.basicConfig(
|
|
81
|
-
level=log_level_map.get(args.log_level, logging.INFO),
|
|
82
|
-
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s"
|
|
83
|
-
)
|
|
84
|
-
logging.info(f"Starting Hindsight API on {args.host}:{args.port}")
|
|
85
|
-
|
|
86
|
-
app_ref = "hindsight_api.web.server:app"
|
|
87
|
-
|
|
88
|
-
# Prepare uvicorn config
|
|
89
|
-
uvicorn_config = {
|
|
90
|
-
"app": app_ref,
|
|
91
|
-
"host": args.host,
|
|
92
|
-
"port": args.port,
|
|
93
|
-
"reload": args.reload,
|
|
94
|
-
"workers": args.workers,
|
|
95
|
-
"log_level": args.log_level,
|
|
96
|
-
"access_log": args.access_log,
|
|
97
|
-
"proxy_headers": args.proxy_headers,
|
|
98
|
-
"ws": "wsproto", # Use wsproto instead of websockets to avoid deprecation warnings
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
# Add optional parameters if provided
|
|
102
|
-
if args.forwarded_allow_ips:
|
|
103
|
-
uvicorn_config["forwarded_allow_ips"] = args.forwarded_allow_ips
|
|
104
|
-
if args.ssl_keyfile:
|
|
105
|
-
uvicorn_config["ssl_keyfile"] = args.ssl_keyfile
|
|
106
|
-
if args.ssl_certfile:
|
|
107
|
-
uvicorn_config["ssl_certfile"] = args.ssl_certfile
|
|
108
|
-
|
|
109
|
-
uvicorn.run(**uvicorn_config)
|
|
File without changes
|