cortexdb-client 0.1.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.
@@ -0,0 +1,140 @@
1
+ # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2
+ """Client and server classes corresponding to protobuf-defined services."""
3
+ import grpc
4
+ import warnings
5
+
6
+ from cortexdb_client._pb.cortexdb.v1 import tools_pb2 as cortexdb_dot_v1_dot_tools__pb2
7
+
8
+ GRPC_GENERATED_VERSION = '1.81.0'
9
+ GRPC_VERSION = grpc.__version__
10
+ _version_not_supported = False
11
+
12
+ try:
13
+ from grpc._utilities import first_version_is_lower
14
+ _version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
15
+ except ImportError:
16
+ _version_not_supported = True
17
+
18
+ if _version_not_supported:
19
+ raise RuntimeError(
20
+ f'The grpc package installed is at version {GRPC_VERSION},'
21
+ + ' but the generated code in cortexdb/v1/tools_pb2_grpc.py depends on'
22
+ + f' grpcio>={GRPC_GENERATED_VERSION}.'
23
+ + f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
24
+ + f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
25
+ )
26
+
27
+
28
+ class ToolsServiceStub:
29
+ """Missing associated documentation comment in .proto file."""
30
+
31
+ def __init__(self, channel):
32
+ """Constructor.
33
+
34
+ Args:
35
+ channel: A grpc.Channel.
36
+ """
37
+ self.ListTools = channel.unary_unary(
38
+ '/cortexdb.v1.ToolsService/ListTools',
39
+ request_serializer=cortexdb_dot_v1_dot_tools__pb2.ListToolsRequest.SerializeToString,
40
+ response_deserializer=cortexdb_dot_v1_dot_tools__pb2.ListToolsResponse.FromString,
41
+ _registered_method=True)
42
+ self.CallTool = channel.unary_unary(
43
+ '/cortexdb.v1.ToolsService/CallTool',
44
+ request_serializer=cortexdb_dot_v1_dot_tools__pb2.CallToolRequest.SerializeToString,
45
+ response_deserializer=cortexdb_dot_v1_dot_tools__pb2.CallToolResponse.FromString,
46
+ _registered_method=True)
47
+
48
+
49
+ class ToolsServiceServicer:
50
+ """Missing associated documentation comment in .proto file."""
51
+
52
+ def ListTools(self, request, context):
53
+ """Missing associated documentation comment in .proto file."""
54
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
55
+ context.set_details('Method not implemented!')
56
+ raise NotImplementedError('Method not implemented!')
57
+
58
+ def CallTool(self, request, context):
59
+ """Missing associated documentation comment in .proto file."""
60
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
61
+ context.set_details('Method not implemented!')
62
+ raise NotImplementedError('Method not implemented!')
63
+
64
+
65
+ def add_ToolsServiceServicer_to_server(servicer, server):
66
+ rpc_method_handlers = {
67
+ 'ListTools': grpc.unary_unary_rpc_method_handler(
68
+ servicer.ListTools,
69
+ request_deserializer=cortexdb_dot_v1_dot_tools__pb2.ListToolsRequest.FromString,
70
+ response_serializer=cortexdb_dot_v1_dot_tools__pb2.ListToolsResponse.SerializeToString,
71
+ ),
72
+ 'CallTool': grpc.unary_unary_rpc_method_handler(
73
+ servicer.CallTool,
74
+ request_deserializer=cortexdb_dot_v1_dot_tools__pb2.CallToolRequest.FromString,
75
+ response_serializer=cortexdb_dot_v1_dot_tools__pb2.CallToolResponse.SerializeToString,
76
+ ),
77
+ }
78
+ generic_handler = grpc.method_handlers_generic_handler(
79
+ 'cortexdb.v1.ToolsService', rpc_method_handlers)
80
+ server.add_generic_rpc_handlers((generic_handler,))
81
+ server.add_registered_method_handlers('cortexdb.v1.ToolsService', rpc_method_handlers)
82
+
83
+
84
+ # This class is part of an EXPERIMENTAL API.
85
+ class ToolsService:
86
+ """Missing associated documentation comment in .proto file."""
87
+
88
+ @staticmethod
89
+ def ListTools(request,
90
+ target,
91
+ options=(),
92
+ channel_credentials=None,
93
+ call_credentials=None,
94
+ insecure=False,
95
+ compression=None,
96
+ wait_for_ready=None,
97
+ timeout=None,
98
+ metadata=None):
99
+ return grpc.experimental.unary_unary(
100
+ request,
101
+ target,
102
+ '/cortexdb.v1.ToolsService/ListTools',
103
+ cortexdb_dot_v1_dot_tools__pb2.ListToolsRequest.SerializeToString,
104
+ cortexdb_dot_v1_dot_tools__pb2.ListToolsResponse.FromString,
105
+ options,
106
+ channel_credentials,
107
+ insecure,
108
+ call_credentials,
109
+ compression,
110
+ wait_for_ready,
111
+ timeout,
112
+ metadata,
113
+ _registered_method=True)
114
+
115
+ @staticmethod
116
+ def CallTool(request,
117
+ target,
118
+ options=(),
119
+ channel_credentials=None,
120
+ call_credentials=None,
121
+ insecure=False,
122
+ compression=None,
123
+ wait_for_ready=None,
124
+ timeout=None,
125
+ metadata=None):
126
+ return grpc.experimental.unary_unary(
127
+ request,
128
+ target,
129
+ '/cortexdb.v1.ToolsService/CallTool',
130
+ cortexdb_dot_v1_dot_tools__pb2.CallToolRequest.SerializeToString,
131
+ cortexdb_dot_v1_dot_tools__pb2.CallToolResponse.FromString,
132
+ options,
133
+ channel_credentials,
134
+ insecure,
135
+ call_credentials,
136
+ compression,
137
+ wait_for_ready,
138
+ timeout,
139
+ metadata,
140
+ _registered_method=True)
@@ -0,0 +1,80 @@
1
+ """The CortexClient facade — mirrors the Rust crate's sub-client layout."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ import grpc
8
+
9
+ from ._pb.cortexdb.v1 import admin_pb2_grpc, graph_pb2_grpc, graphrag_pb2_grpc
10
+ from ._pb.cortexdb.v1 import knowledge_pb2_grpc, memory_pb2_grpc, tools_pb2_grpc
11
+
12
+
13
+ def _bearer_interceptor(token: str) -> grpc.UnaryUnaryClientInterceptor:
14
+ """Attach ``authorization: Bearer <token>`` to every unary call."""
15
+
16
+ class _Interceptor(grpc.UnaryUnaryClientInterceptor):
17
+ def intercept_unary_unary(self, continuation, client_call_details, request):
18
+ metadata = list(client_call_details.metadata or [])
19
+ metadata.append(("authorization", f"Bearer {token}"))
20
+ new_details = client_call_details._replace(metadata=metadata)
21
+ return continuation(new_details, request)
22
+
23
+ return _Interceptor()
24
+
25
+
26
+ class CortexClient:
27
+ """One connection to a CortexDB sidecar, exposing all service clients.
28
+
29
+ Construct with :meth:`connect`. Use as a context manager to close the
30
+ channel automatically, or call :meth:`close` yourself.
31
+ """
32
+
33
+ def __init__(self, channel: grpc.Channel):
34
+ self._channel = channel
35
+ self.knowledge = knowledge_pb2_grpc.KnowledgeServiceStub(channel)
36
+ self.memory = memory_pb2_grpc.MemoryServiceStub(channel)
37
+ self.graph = graph_pb2_grpc.KnowledgeGraphServiceStub(channel)
38
+ self.graphrag = graphrag_pb2_grpc.GraphRagServiceStub(channel)
39
+ self.tools = tools_pb2_grpc.ToolsServiceStub(channel)
40
+ self.admin = admin_pb2_grpc.AdminServiceStub(channel)
41
+
42
+ @classmethod
43
+ def connect(
44
+ cls,
45
+ endpoint: str,
46
+ token: Optional[str] = None,
47
+ *,
48
+ secure: bool = False,
49
+ credentials: Optional[grpc.ChannelCredentials] = None,
50
+ ) -> "CortexClient":
51
+ """Connect to ``endpoint`` (``host:port``, optional ``http(s)://`` prefix).
52
+
53
+ Pass ``token`` to authenticate every request with a bearer token. The
54
+ sidecar listens on plaintext by default; set ``secure=True`` (and
55
+ optionally ``credentials``) when fronting it with TLS.
56
+ """
57
+ target = endpoint
58
+ for prefix in ("http://", "https://"):
59
+ if target.startswith(prefix):
60
+ target = target[len(prefix):]
61
+ break
62
+
63
+ if secure:
64
+ channel = grpc.secure_channel(target, credentials or grpc.ssl_channel_credentials())
65
+ else:
66
+ channel = grpc.insecure_channel(target)
67
+
68
+ if token:
69
+ channel = grpc.intercept_channel(channel, _bearer_interceptor(token))
70
+
71
+ return cls(channel)
72
+
73
+ def close(self) -> None:
74
+ self._channel.close()
75
+
76
+ def __enter__(self) -> "CortexClient":
77
+ return self
78
+
79
+ def __exit__(self, *exc) -> None:
80
+ self.close()
@@ -0,0 +1,24 @@
1
+ """Re-exports of the generated ``cortexdb.v1`` protobuf message types.
2
+
3
+ Use these as ``proto.SaveKnowledgeRequest(...)`` etc. The grpc service stubs
4
+ live alongside but are wired up by :mod:`cortexdb_client.client`; application
5
+ code should only need the message types from here.
6
+ """
7
+
8
+ from ._pb.cortexdb.v1 import common_pb2 as _common
9
+ from ._pb.cortexdb.v1 import knowledge_pb2 as _knowledge
10
+ from ._pb.cortexdb.v1 import memory_pb2 as _memory
11
+ from ._pb.cortexdb.v1 import graph_pb2 as _graph
12
+ from ._pb.cortexdb.v1 import graphrag_pb2 as _graphrag
13
+ from ._pb.cortexdb.v1 import tools_pb2 as _tools
14
+ from ._pb.cortexdb.v1 import admin_pb2 as _admin
15
+
16
+ _modules = (_common, _knowledge, _memory, _graph, _graphrag, _tools, _admin)
17
+
18
+ # Flatten every generated message class into this module's namespace so callers
19
+ # can write proto.SaveKnowledgeRequest instead of knowledge_pb2.SaveKnowledgeRequest.
20
+ __all__ = []
21
+ for _m in _modules:
22
+ for _name in getattr(_m, "DESCRIPTOR").message_types_by_name:
23
+ globals()[_name] = getattr(_m, _name)
24
+ __all__.append(_name)
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: cortexdb-client
3
+ Version: 0.1.0
4
+ Summary: Typed gRPC client for CortexDB (AI memory + knowledge graph sidecar)
5
+ Project-URL: Homepage, https://github.com/liliang-cn/cortexdb
6
+ Project-URL: Repository, https://github.com/liliang-cn/cortexdb
7
+ Author: Liang Li
8
+ License: MIT
9
+ Keywords: agent-memory,ai,cortexdb,grpc,knowledge-graph,rag
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Database
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.9
15
+ Requires-Dist: grpcio>=1.60
16
+ Requires-Dist: protobuf>=4.25
17
+ Provides-Extra: dev
18
+ Requires-Dist: build; extra == 'dev'
19
+ Requires-Dist: grpcio-tools>=1.60; extra == 'dev'
20
+ Requires-Dist: twine; extra == 'dev'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # cortexdb-client (Python)
24
+
25
+ Typed gRPC client for [CortexDB](https://github.com/liliang-cn/cortexdb) — a
26
+ pure-Go, single-file AI memory and knowledge graph database, served as a
27
+ sidecar (`cortexdb-grpc`). Give your Python agent (e.g. **Hermes**) durable
28
+ memory **and** a queryable knowledge graph.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pip install cortexdb-client # or: uv add cortexdb-client
34
+ ```
35
+
36
+ Start the sidecar (one binary, one SQLite file):
37
+
38
+ ```bash
39
+ go install github.com/liliang-cn/cortexdb/v2/cmd/cortexdb-grpc@latest
40
+ CORTEXDB_PATH=agent.db CORTEXDB_GRPC_TOKEN=s3cret cortexdb-grpc
41
+ # listening on 127.0.0.1:47821
42
+ ```
43
+
44
+ ## Quick start
45
+
46
+ ```python
47
+ from cortexdb_client import CortexClient, proto
48
+
49
+ with CortexClient.connect("127.0.0.1:47821", token="s3cret") as client:
50
+ client.knowledge.SaveKnowledge(proto.SaveKnowledgeRequest(
51
+ knowledge_id="note-1",
52
+ content="The user is building an autonomous research agent in Python.",
53
+ ))
54
+ hits = client.knowledge.SearchKnowledge(proto.SearchKnowledgeRequest(
55
+ query="what is the user building?", top_k=3,
56
+ ))
57
+ for h in hits.results:
58
+ print(h.knowledge_id, h.score, h.snippet)
59
+ ```
60
+
61
+ Sub-clients mirror the Rust crate: `client.knowledge`, `client.memory`,
62
+ `client.graph` (SPARQL/RDF/SHACL/inference/ontology), `client.graphrag`,
63
+ `client.tools` (generic tool dispatch, same surface as MCP), `client.admin`.
64
+
65
+ ## Why a knowledge graph, not just vectors
66
+
67
+ Beyond semantic recall, the `graph` service lets an agent store and traverse
68
+ **entities and relations** — multi-hop questions like "who, among the people
69
+ Alice knows, works on X" — with SPARQL, RDFS-lite inference, and SHACL-lite
70
+ validation. That is the capability most agent-memory layers lack.
71
+
72
+ ## Embeddings
73
+
74
+ Lexical mode needs no keys. Point the sidecar at any OpenAI-compatible
75
+ embeddings endpoint (e.g. Ollama) to enable vector retrieval:
76
+
77
+ ```bash
78
+ OPENAI_BASE_URL=http://localhost:11434/v1 \
79
+ CORTEXDB_EMBED_MODEL=embeddinggemma CORTEXDB_EMBED_DIM=768 \
80
+ cortexdb-grpc
81
+ ```
82
+
83
+ ## Regenerating the protobuf code
84
+
85
+ Generated code is committed under `cortexdb_client/_pb`. To regenerate after a
86
+ proto change: `uv run --extra dev ./gen.sh`.
@@ -0,0 +1,23 @@
1
+ cortexdb_client/__init__.py,sha256=nsOEhmpqzVrrFUJfRb4GQ3S1JPei625oiP4TApzOYxI,784
2
+ cortexdb_client/client.py,sha256=NRRC9CVOnZzbClZRTehjXIPg51vAZ8bAtR6W_GrUK4s,2846
3
+ cortexdb_client/proto.py,sha256=sJMNaSoLgoliJ5I4IRztWC-14f6LfjGnjaxUEN0_4oM,1064
4
+ cortexdb_client/_pb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ cortexdb_client/_pb/cortexdb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ cortexdb_client/_pb/cortexdb/v1/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ cortexdb_client/_pb/cortexdb/v1/admin_pb2.py,sha256=gm39Tljd0iEuYElFrjbQBobvqhLUv-fRTm3IE2qucFQ,2275
8
+ cortexdb_client/_pb/cortexdb/v1/admin_pb2_grpc.py,sha256=fhkvXsb13R0PZAlHfVOQic1vGC7kZ_gLCDiaF5S1cCA,5276
9
+ cortexdb_client/_pb/cortexdb/v1/common_pb2.py,sha256=eL8eUb6ukDbqn-mB4Cus33Ic3CMLAOuMh9TIhBgtxJk,4619
10
+ cortexdb_client/_pb/cortexdb/v1/common_pb2_grpc.py,sha256=tZbcHDkTGGGegvbUgSnfUxQtkbSxi2-Vf4dEqPLEPXM,898
11
+ cortexdb_client/_pb/cortexdb/v1/graph_pb2.py,sha256=voKi1pdozp_rdu1_6ztcx8WdJ-ffL4xIStGFZh4yz84,19806
12
+ cortexdb_client/_pb/cortexdb/v1/graph_pb2_grpc.py,sha256=8RQaJfoJZppxcrgR1VfGgQeqBiv1_UHq02pU1C3VLtE,34494
13
+ cortexdb_client/_pb/cortexdb/v1/graphrag_pb2.py,sha256=xj6DWnJwb-pnD5jn_WQg3Ls5SBgjmKDhCWfCMDFZ8SE,8731
14
+ cortexdb_client/_pb/cortexdb/v1/graphrag_pb2_grpc.py,sha256=tvcbJaNZycqL0t-XMMEOX75FoHP8Gn3Oc1tp3p3E-KA,13113
15
+ cortexdb_client/_pb/cortexdb/v1/knowledge_pb2.py,sha256=ayfvcKU4VRQoH9HjQeriTOJHoZ0bfKDngPjnFcqVpbg,9618
16
+ cortexdb_client/_pb/cortexdb/v1/knowledge_pb2_grpc.py,sha256=2ilQ73FbQsoUq1JoobGH-P8RGNEysHAs_i2Piz4FAyQ,11274
17
+ cortexdb_client/_pb/cortexdb/v1/memory_pb2.py,sha256=pzU0tAHQjL6oJ0TYiGCHfSnyAG2Z0_4uDaW6D2UHsEI,6246
18
+ cortexdb_client/_pb/cortexdb/v1/memory_pb2_grpc.py,sha256=dYmm8pqNNqAYBQW9IDuo3XZpd0Y5yKOD_JjAjewdHLE,10932
19
+ cortexdb_client/_pb/cortexdb/v1/tools_pb2.py,sha256=3p0s0bd84LhEb1Z8_lcoFSS0LXuNEW-5D4wi9aR92GI,2623
20
+ cortexdb_client/_pb/cortexdb/v1/tools_pb2_grpc.py,sha256=jOSBnUfigrrcYKaoozkqEB92ARefiVVkT1Fyg5aq3a4,5367
21
+ cortexdb_client-0.1.0.dist-info/METADATA,sha256=PTqrtZPnGxi_L_9UBvaLYCxsq55z1MdiNl-frw2p0gc,2991
22
+ cortexdb_client-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
23
+ cortexdb_client-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any