remdb 0.3.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.
Potentially problematic release.
This version of remdb might be problematic. Click here for more details.
- rem/__init__.py +2 -0
- rem/agentic/README.md +650 -0
- rem/agentic/__init__.py +39 -0
- rem/agentic/agents/README.md +155 -0
- rem/agentic/agents/__init__.py +8 -0
- rem/agentic/context.py +148 -0
- rem/agentic/context_builder.py +329 -0
- rem/agentic/mcp/__init__.py +0 -0
- rem/agentic/mcp/tool_wrapper.py +107 -0
- rem/agentic/otel/__init__.py +5 -0
- rem/agentic/otel/setup.py +151 -0
- rem/agentic/providers/phoenix.py +674 -0
- rem/agentic/providers/pydantic_ai.py +572 -0
- rem/agentic/query.py +117 -0
- rem/agentic/query_helper.py +89 -0
- rem/agentic/schema.py +396 -0
- rem/agentic/serialization.py +245 -0
- rem/agentic/tools/__init__.py +5 -0
- rem/agentic/tools/rem_tools.py +231 -0
- rem/api/README.md +420 -0
- rem/api/main.py +324 -0
- rem/api/mcp_router/prompts.py +182 -0
- rem/api/mcp_router/resources.py +536 -0
- rem/api/mcp_router/server.py +213 -0
- rem/api/mcp_router/tools.py +584 -0
- rem/api/routers/auth.py +229 -0
- rem/api/routers/chat/__init__.py +5 -0
- rem/api/routers/chat/completions.py +281 -0
- rem/api/routers/chat/json_utils.py +76 -0
- rem/api/routers/chat/models.py +124 -0
- rem/api/routers/chat/streaming.py +185 -0
- rem/auth/README.md +258 -0
- rem/auth/__init__.py +26 -0
- rem/auth/middleware.py +100 -0
- rem/auth/providers/__init__.py +13 -0
- rem/auth/providers/base.py +376 -0
- rem/auth/providers/google.py +163 -0
- rem/auth/providers/microsoft.py +237 -0
- rem/cli/README.md +455 -0
- rem/cli/__init__.py +8 -0
- rem/cli/commands/README.md +126 -0
- rem/cli/commands/__init__.py +3 -0
- rem/cli/commands/ask.py +566 -0
- rem/cli/commands/configure.py +497 -0
- rem/cli/commands/db.py +493 -0
- rem/cli/commands/dreaming.py +324 -0
- rem/cli/commands/experiments.py +1302 -0
- rem/cli/commands/mcp.py +66 -0
- rem/cli/commands/process.py +245 -0
- rem/cli/commands/schema.py +183 -0
- rem/cli/commands/serve.py +106 -0
- rem/cli/dreaming.py +363 -0
- rem/cli/main.py +96 -0
- rem/config.py +237 -0
- rem/mcp_server.py +41 -0
- rem/models/core/__init__.py +49 -0
- rem/models/core/core_model.py +64 -0
- rem/models/core/engram.py +333 -0
- rem/models/core/experiment.py +628 -0
- rem/models/core/inline_edge.py +132 -0
- rem/models/core/rem_query.py +243 -0
- rem/models/entities/__init__.py +43 -0
- rem/models/entities/file.py +57 -0
- rem/models/entities/image_resource.py +88 -0
- rem/models/entities/message.py +35 -0
- rem/models/entities/moment.py +123 -0
- rem/models/entities/ontology.py +191 -0
- rem/models/entities/ontology_config.py +131 -0
- rem/models/entities/resource.py +95 -0
- rem/models/entities/schema.py +87 -0
- rem/models/entities/user.py +85 -0
- rem/py.typed +0 -0
- rem/schemas/README.md +507 -0
- rem/schemas/__init__.py +6 -0
- rem/schemas/agents/README.md +92 -0
- rem/schemas/agents/core/moment-builder.yaml +178 -0
- rem/schemas/agents/core/rem-query-agent.yaml +226 -0
- rem/schemas/agents/core/resource-affinity-assessor.yaml +99 -0
- rem/schemas/agents/core/simple-assistant.yaml +19 -0
- rem/schemas/agents/core/user-profile-builder.yaml +163 -0
- rem/schemas/agents/examples/contract-analyzer.yaml +317 -0
- rem/schemas/agents/examples/contract-extractor.yaml +134 -0
- rem/schemas/agents/examples/cv-parser.yaml +263 -0
- rem/schemas/agents/examples/hello-world.yaml +37 -0
- rem/schemas/agents/examples/query.yaml +54 -0
- rem/schemas/agents/examples/simple.yaml +21 -0
- rem/schemas/agents/examples/test.yaml +29 -0
- rem/schemas/agents/rem.yaml +128 -0
- rem/schemas/evaluators/hello-world/default.yaml +77 -0
- rem/schemas/evaluators/rem/faithfulness.yaml +219 -0
- rem/schemas/evaluators/rem/lookup-correctness.yaml +182 -0
- rem/schemas/evaluators/rem/retrieval-precision.yaml +199 -0
- rem/schemas/evaluators/rem/retrieval-recall.yaml +211 -0
- rem/schemas/evaluators/rem/search-correctness.yaml +192 -0
- rem/services/__init__.py +16 -0
- rem/services/audio/INTEGRATION.md +308 -0
- rem/services/audio/README.md +376 -0
- rem/services/audio/__init__.py +15 -0
- rem/services/audio/chunker.py +354 -0
- rem/services/audio/transcriber.py +259 -0
- rem/services/content/README.md +1269 -0
- rem/services/content/__init__.py +5 -0
- rem/services/content/providers.py +806 -0
- rem/services/content/service.py +676 -0
- rem/services/dreaming/README.md +230 -0
- rem/services/dreaming/__init__.py +53 -0
- rem/services/dreaming/affinity_service.py +336 -0
- rem/services/dreaming/moment_service.py +264 -0
- rem/services/dreaming/ontology_service.py +54 -0
- rem/services/dreaming/user_model_service.py +297 -0
- rem/services/dreaming/utils.py +39 -0
- rem/services/embeddings/__init__.py +11 -0
- rem/services/embeddings/api.py +120 -0
- rem/services/embeddings/worker.py +421 -0
- rem/services/fs/README.md +662 -0
- rem/services/fs/__init__.py +62 -0
- rem/services/fs/examples.py +206 -0
- rem/services/fs/examples_paths.py +204 -0
- rem/services/fs/git_provider.py +935 -0
- rem/services/fs/local_provider.py +760 -0
- rem/services/fs/parsing-hooks-examples.md +172 -0
- rem/services/fs/paths.py +276 -0
- rem/services/fs/provider.py +460 -0
- rem/services/fs/s3_provider.py +1042 -0
- rem/services/fs/service.py +186 -0
- rem/services/git/README.md +1075 -0
- rem/services/git/__init__.py +17 -0
- rem/services/git/service.py +469 -0
- rem/services/phoenix/EXPERIMENT_DESIGN.md +1146 -0
- rem/services/phoenix/README.md +453 -0
- rem/services/phoenix/__init__.py +46 -0
- rem/services/phoenix/client.py +686 -0
- rem/services/phoenix/config.py +88 -0
- rem/services/phoenix/prompt_labels.py +477 -0
- rem/services/postgres/README.md +575 -0
- rem/services/postgres/__init__.py +23 -0
- rem/services/postgres/migration_service.py +427 -0
- rem/services/postgres/pydantic_to_sqlalchemy.py +232 -0
- rem/services/postgres/register_type.py +352 -0
- rem/services/postgres/repository.py +337 -0
- rem/services/postgres/schema_generator.py +379 -0
- rem/services/postgres/service.py +802 -0
- rem/services/postgres/sql_builder.py +354 -0
- rem/services/rem/README.md +304 -0
- rem/services/rem/__init__.py +23 -0
- rem/services/rem/exceptions.py +71 -0
- rem/services/rem/executor.py +293 -0
- rem/services/rem/parser.py +145 -0
- rem/services/rem/queries.py +196 -0
- rem/services/rem/query.py +371 -0
- rem/services/rem/service.py +527 -0
- rem/services/session/README.md +374 -0
- rem/services/session/__init__.py +6 -0
- rem/services/session/compression.py +360 -0
- rem/services/session/reload.py +77 -0
- rem/settings.py +1235 -0
- rem/sql/002_install_models.sql +1068 -0
- rem/sql/background_indexes.sql +42 -0
- rem/sql/install_models.sql +1038 -0
- rem/sql/migrations/001_install.sql +503 -0
- rem/sql/migrations/002_install_models.sql +1202 -0
- rem/utils/AGENTIC_CHUNKING.md +597 -0
- rem/utils/README.md +583 -0
- rem/utils/__init__.py +43 -0
- rem/utils/agentic_chunking.py +622 -0
- rem/utils/batch_ops.py +343 -0
- rem/utils/chunking.py +108 -0
- rem/utils/clip_embeddings.py +276 -0
- rem/utils/dict_utils.py +98 -0
- rem/utils/embeddings.py +423 -0
- rem/utils/examples/embeddings_example.py +305 -0
- rem/utils/examples/sql_types_example.py +202 -0
- rem/utils/markdown.py +16 -0
- rem/utils/model_helpers.py +236 -0
- rem/utils/schema_loader.py +336 -0
- rem/utils/sql_types.py +348 -0
- rem/utils/user_id.py +81 -0
- rem/utils/vision.py +330 -0
- rem/workers/README.md +506 -0
- rem/workers/__init__.py +5 -0
- rem/workers/dreaming.py +502 -0
- rem/workers/engram_processor.py +312 -0
- rem/workers/sqs_file_processor.py +193 -0
- remdb-0.3.0.dist-info/METADATA +1455 -0
- remdb-0.3.0.dist-info/RECORD +187 -0
- remdb-0.3.0.dist-info/WHEEL +4 -0
- remdb-0.3.0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MCP server creation and configuration for REM.
|
|
3
|
+
|
|
4
|
+
Design Pattern
|
|
5
|
+
1. Create FastMCP server with tools and resources
|
|
6
|
+
2. Register tools using @mcp.tool() decorator
|
|
7
|
+
3. Register resources using resource registration functions
|
|
8
|
+
4. Mount on FastAPI at /api/v1/mcp
|
|
9
|
+
5. Support both HTTP and SSE transports
|
|
10
|
+
|
|
11
|
+
Key Concepts:
|
|
12
|
+
- Tools: Functions LLM can call (search, query, parse, etc.)
|
|
13
|
+
- Resources: Read-only data sources (entity lookups, schema docs, etc.)
|
|
14
|
+
- Instructions: System-level guidance for LLM on how to use MCP server
|
|
15
|
+
|
|
16
|
+
FastMCP Features:
|
|
17
|
+
- Stateless HTTP mode (stateless_http=True) prevents stale session errors
|
|
18
|
+
- Path="/" creates routes at root, then mount at custom path
|
|
19
|
+
- Built-in auth that can be disabled for testing
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from fastmcp import FastMCP
|
|
23
|
+
|
|
24
|
+
from ...settings import settings
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def create_mcp_server(is_local: bool = False) -> FastMCP:
|
|
28
|
+
"""
|
|
29
|
+
Create and configure the REM MCP server with all tools and resources.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
is_local: True if running as local/stdio server (enables file ingestion from local paths)
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Configured FastMCP server instance
|
|
36
|
+
|
|
37
|
+
Usage Modes:
|
|
38
|
+
# Stdio mode (for local dev / Claude Desktop)
|
|
39
|
+
mcp = create_mcp_server(is_local=True)
|
|
40
|
+
mcp.run(transport="stdio")
|
|
41
|
+
|
|
42
|
+
# HTTP mode (for production / API)
|
|
43
|
+
mcp = create_mcp_server(is_local=False)
|
|
44
|
+
mcp_app = mcp.http_app(path="/", transport="http", stateless_http=True)
|
|
45
|
+
# Then mount: app.mount("/api/v1/mcp", mcp_app)
|
|
46
|
+
|
|
47
|
+
Design Pattern
|
|
48
|
+
- Instructions provide LLM guidance on workflow
|
|
49
|
+
- Tools implement specific operations
|
|
50
|
+
- Resources provide read-only access to data
|
|
51
|
+
- All modular and testable
|
|
52
|
+
"""
|
|
53
|
+
mcp = FastMCP(
|
|
54
|
+
name=f"REM MCP Server ({settings.team}/{settings.environment})",
|
|
55
|
+
version="0.1.0",
|
|
56
|
+
instructions=(
|
|
57
|
+
"REM (Resource-Entity-Moment) MCP Server - Unified memory infrastructure for agentic systems.\n\n"
|
|
58
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
59
|
+
"REM QUERY WORKFLOW - Schema-Agnostic Natural Language Queries\n"
|
|
60
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
61
|
+
"\n"
|
|
62
|
+
"**IMPORTANT:** REM uses natural language labels, NOT UUIDs. You query with:\n"
|
|
63
|
+
"- LOOKUP \"Sarah Chen\" (what user knows)\n"
|
|
64
|
+
"- NOT LOOKUP \"sarah-chen-uuid-1234\" (internal ID)\n"
|
|
65
|
+
"\n"
|
|
66
|
+
"REM Query Types:\n"
|
|
67
|
+
"\n"
|
|
68
|
+
"1. LOOKUP - O(1) entity resolution across ALL tables\n"
|
|
69
|
+
" Example: LOOKUP \"Sarah Chen\"\n"
|
|
70
|
+
" Returns: All entities named \"Sarah Chen\" (resources, moments, users)\n"
|
|
71
|
+
"\n"
|
|
72
|
+
"2. FUZZY - Indexed fuzzy text matching\n"
|
|
73
|
+
" Example: FUZZY \"sara\" threshold=0.7\n"
|
|
74
|
+
" Returns: \"Sarah Chen\", \"Sara Martinez\", etc.\n"
|
|
75
|
+
"\n"
|
|
76
|
+
"3. SEARCH - Semantic vector search (table-specific)\n"
|
|
77
|
+
" Example: SEARCH \"database migration\" table=resources\n"
|
|
78
|
+
" Returns: Semantically similar resources\n"
|
|
79
|
+
"\n"
|
|
80
|
+
"4. SQL - Direct table queries with WHERE clauses\n"
|
|
81
|
+
" Example: SQL table=moments WHERE moment_type='meeting'\n"
|
|
82
|
+
" Returns: All meeting moments\n"
|
|
83
|
+
"\n"
|
|
84
|
+
"5. TRAVERSE - Multi-hop graph traversal\n"
|
|
85
|
+
" Example: TRAVERSE manages WITH LOOKUP \"Sally\" DEPTH 2\n"
|
|
86
|
+
" Returns: Sally + her team hierarchy\n"
|
|
87
|
+
"\n"
|
|
88
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
89
|
+
"ITERATED RETRIEVAL PATTERN - Multi-Turn Exploration\n"
|
|
90
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
91
|
+
"\n"
|
|
92
|
+
"REM is designed for multi-turn exploration, not single-shot queries:\n"
|
|
93
|
+
"\n"
|
|
94
|
+
"Turn 1: Find entry point\n"
|
|
95
|
+
" LOOKUP \"Sarah Chen\"\n"
|
|
96
|
+
" → Found person entity with 3 graph edges\n"
|
|
97
|
+
"\n"
|
|
98
|
+
"Turn 2: Analyze neighborhood (PLAN mode - depth 0)\n"
|
|
99
|
+
" ask_rem(\"What are Sarah Chen's connections?\", plan_mode=True)\n"
|
|
100
|
+
" → Agent uses TRAVERSE with max_depth=0\n"
|
|
101
|
+
" → Edge summary: manages(2), authored_by(15), mentors(3)\n"
|
|
102
|
+
"\n"
|
|
103
|
+
"Turn 3: Selective traversal\n"
|
|
104
|
+
" ask_rem(\"Show Sarah Chen's team hierarchy\")\n"
|
|
105
|
+
" → Agent uses TRAVERSE with rel_type=\"manages\", max_depth=2\n"
|
|
106
|
+
" → Returns: Sarah + team hierarchy (depth 2)\n"
|
|
107
|
+
"\n"
|
|
108
|
+
"Turn 4: Follow reference chain\n"
|
|
109
|
+
" TRAVERSE references,builds-on WITH LOOKUP \"api-design-v2\" DEPTH 1\n"
|
|
110
|
+
" → Returns: Design lineage\n"
|
|
111
|
+
"\n"
|
|
112
|
+
"**Key Concepts:**\n"
|
|
113
|
+
"- Depth 0 = PLAN mode (analyze edges without traversal)\n"
|
|
114
|
+
"- Depth 1+ = Full traversal with cycle detection\n"
|
|
115
|
+
"- Plan memo = Agent scratchpad for multi-turn tracking\n"
|
|
116
|
+
"- Edge filters = Selective relationship types\n"
|
|
117
|
+
"\n"
|
|
118
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
119
|
+
"AVAILABLE TOOLS\n"
|
|
120
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
121
|
+
"\n"
|
|
122
|
+
"• rem_query - Execute REM queries (LOOKUP, FUZZY, SEARCH, SQL, TRAVERSE)\n"
|
|
123
|
+
"• ask_rem - Natural language to REM query conversion\n"
|
|
124
|
+
" - plan_mode=True: Hints agent to use TRAVERSE with depth=0 for edge analysis\n"
|
|
125
|
+
"• parse_and_ingest_file - Ingest files from local paths (local server only), s3://, or https://\n"
|
|
126
|
+
"\n"
|
|
127
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
128
|
+
"AVAILABLE RESOURCES (Read-Only)\n"
|
|
129
|
+
"═══════════════════════════════════════════════════════════════════════════\n"
|
|
130
|
+
"\n"
|
|
131
|
+
"Schema Information:\n"
|
|
132
|
+
"• rem://schema/entities - Entity schemas (Resource, Message, User, File, Moment)\n"
|
|
133
|
+
"• rem://schema/query-types - REM query type documentation\n"
|
|
134
|
+
"\n"
|
|
135
|
+
"Agent Schemas:\n"
|
|
136
|
+
"• rem://agents - List available agent schemas with descriptions and usage\n"
|
|
137
|
+
"\n"
|
|
138
|
+
"File Operations:\n"
|
|
139
|
+
"• rem://files/presigned-url - Generate presigned S3 URLs for file download\n"
|
|
140
|
+
"\n"
|
|
141
|
+
"System Status:\n"
|
|
142
|
+
"• rem://status - System health and statistics\n"
|
|
143
|
+
"\n"
|
|
144
|
+
"**Quick Start:**\n"
|
|
145
|
+
"1. User: \"Who is Sarah?\"\n"
|
|
146
|
+
" → Call: search_rem(query_type=\"lookup\", entity_key=\"Sarah\", user_id=\"...\")\n"
|
|
147
|
+
"\n"
|
|
148
|
+
"2. User: \"Find documents about database migration\"\n"
|
|
149
|
+
" → Call: search_rem(query_type=\"search\", query_text=\"database migration\", table=\"resources\", user_id=\"...\")\n"
|
|
150
|
+
"\n"
|
|
151
|
+
"3. User: \"Who reports to Sally?\"\n"
|
|
152
|
+
" → Call: search_rem(query_type=\"traverse\", initial_query=\"Sally\", edge_types=[\"reports-to\"], depth=2, user_id=\"...\")\n"
|
|
153
|
+
"\n"
|
|
154
|
+
"4. User: \"Show me Sarah's org chart\" (Multi-turn example)\n"
|
|
155
|
+
" → Turn 1: search_rem(query_type=\"lookup\", entity_key=\"Sarah\", user_id=\"...\")\n"
|
|
156
|
+
" → Turn 2: search_rem(query_type=\"traverse\", initial_query=\"Sarah\", depth=0, user_id=\"...\") # PLAN mode\n"
|
|
157
|
+
" → Turn 3: search_rem(query_type=\"traverse\", initial_query=\"Sarah\", edge_types=[\"manages\", \"reports-to\"], depth=2, user_id=\"...\")\n"
|
|
158
|
+
"\n"
|
|
159
|
+
"5. User: \"What did we discuss last week about the TiDB migration?\"\n"
|
|
160
|
+
" → Call: ask_rem_agent(query=\"What did we discuss last week about the TiDB migration?\", user_id=\"...\")\n"
|
|
161
|
+
"\n"
|
|
162
|
+
"6. User: \"Ingest this PDF file\"\n"
|
|
163
|
+
" → Call: ingest_into_rem(file_uri=\"s3://bucket/file.pdf\", user_id=\"...\")\n"
|
|
164
|
+
),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
# Register REM tools
|
|
168
|
+
from .tools import ask_rem_agent, ingest_into_rem, read_resource, search_rem
|
|
169
|
+
|
|
170
|
+
mcp.tool()(search_rem)
|
|
171
|
+
mcp.tool()(ask_rem_agent)
|
|
172
|
+
mcp.tool()(read_resource)
|
|
173
|
+
|
|
174
|
+
# File ingestion tool (with local path support for local servers)
|
|
175
|
+
# Wrap to inject is_local parameter
|
|
176
|
+
from functools import wraps
|
|
177
|
+
|
|
178
|
+
@wraps(ingest_into_rem)
|
|
179
|
+
async def ingest_into_rem_wrapper(
|
|
180
|
+
file_uri: str,
|
|
181
|
+
user_id: str | None = None,
|
|
182
|
+
category: str | None = None,
|
|
183
|
+
tags: list[str] | None = None,
|
|
184
|
+
):
|
|
185
|
+
return await ingest_into_rem(
|
|
186
|
+
file_uri=file_uri,
|
|
187
|
+
user_id=user_id,
|
|
188
|
+
category=category,
|
|
189
|
+
tags=tags,
|
|
190
|
+
is_local_server=is_local,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
mcp.tool()(ingest_into_rem_wrapper)
|
|
194
|
+
|
|
195
|
+
# Register prompts
|
|
196
|
+
from .prompts import register_prompts
|
|
197
|
+
|
|
198
|
+
register_prompts(mcp)
|
|
199
|
+
|
|
200
|
+
# Register schema resources
|
|
201
|
+
from .resources import (
|
|
202
|
+
register_agent_resources,
|
|
203
|
+
register_file_resources,
|
|
204
|
+
register_schema_resources,
|
|
205
|
+
register_status_resources,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
register_schema_resources(mcp)
|
|
209
|
+
register_agent_resources(mcp)
|
|
210
|
+
register_file_resources(mcp)
|
|
211
|
+
register_status_resources(mcp)
|
|
212
|
+
|
|
213
|
+
return mcp
|