maximem-synap-semantic-kernel 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.
- maximem_synap_semantic_kernel-0.1.1.dist-info/METADATA +12 -0
- maximem_synap_semantic_kernel-0.1.1.dist-info/RECORD +6 -0
- maximem_synap_semantic_kernel-0.1.1.dist-info/WHEEL +5 -0
- maximem_synap_semantic_kernel-0.1.1.dist-info/top_level.txt +1 -0
- synap_semantic_kernel/__init__.py +5 -0
- synap_semantic_kernel/plugin.py +93 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: maximem-synap-semantic-kernel
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Synap memory integration for Microsoft Semantic Kernel
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: maximem-synap>=0.2.0
|
|
8
|
+
Requires-Dist: synap-integrations-common>=0.1.0
|
|
9
|
+
Requires-Dist: semantic-kernel>=1.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
12
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
synap_semantic_kernel/__init__.py,sha256=S808aSAJ-DHyL9ByoQIfs7Ua4hyeMNEj3IPzkPoQfn0,143
|
|
2
|
+
synap_semantic_kernel/plugin.py,sha256=vOhFzDC4wZFh8ydNsSYgN9knG2X0i7tS8ao11hF5tgo,2911
|
|
3
|
+
maximem_synap_semantic_kernel-0.1.1.dist-info/METADATA,sha256=ZGwjklCAURZXpdGvKtiwEPrOjYyoC5Zp_nl3SwehnCo,427
|
|
4
|
+
maximem_synap_semantic_kernel-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
maximem_synap_semantic_kernel-0.1.1.dist-info/top_level.txt,sha256=je8evgxmID56j5mtSX-1Z_xs3YMl7IH8MZuFvW6AqnA,22
|
|
6
|
+
maximem_synap_semantic_kernel-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
synap_semantic_kernel
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Synap plugin for Microsoft Semantic Kernel.
|
|
2
|
+
|
|
3
|
+
Exposes Synap memory as kernel functions (search_memory, store_memory)
|
|
4
|
+
that can be registered with a Semantic Kernel instance.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Annotated, Optional
|
|
9
|
+
|
|
10
|
+
from semantic_kernel.functions import kernel_function
|
|
11
|
+
|
|
12
|
+
from maximem_synap import MaximemSynapSDK
|
|
13
|
+
from synap_integrations_common import wrap_sdk_errors_async
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class SynapPlugin:
|
|
19
|
+
"""Semantic Kernel plugin for Synap memory operations.
|
|
20
|
+
|
|
21
|
+
Example::
|
|
22
|
+
|
|
23
|
+
from semantic_kernel import Kernel
|
|
24
|
+
from synap_semantic_kernel import SynapPlugin
|
|
25
|
+
|
|
26
|
+
kernel = Kernel()
|
|
27
|
+
kernel.add_plugin(
|
|
28
|
+
SynapPlugin(sdk=sdk, user_id="u1"),
|
|
29
|
+
plugin_name="synap",
|
|
30
|
+
)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
sdk: MaximemSynapSDK,
|
|
36
|
+
user_id: str,
|
|
37
|
+
customer_id: str = "",
|
|
38
|
+
conversation_id: Optional[str] = None,
|
|
39
|
+
):
|
|
40
|
+
if sdk is None:
|
|
41
|
+
raise ValueError("SynapPlugin requires a non-None sdk")
|
|
42
|
+
if not user_id:
|
|
43
|
+
raise ValueError("SynapPlugin requires a non-empty user_id")
|
|
44
|
+
|
|
45
|
+
self._sdk = sdk
|
|
46
|
+
self._user_id = user_id
|
|
47
|
+
self._customer_id = customer_id
|
|
48
|
+
self._conversation_id = conversation_id
|
|
49
|
+
|
|
50
|
+
@kernel_function(
|
|
51
|
+
name="search_memory",
|
|
52
|
+
description=(
|
|
53
|
+
"Search the user's memory for relevant context. Use when you need "
|
|
54
|
+
"to recall past conversations, preferences, or facts about the user."
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
async def search_memory(
|
|
58
|
+
self,
|
|
59
|
+
query: Annotated[str, "Natural language search query"],
|
|
60
|
+
) -> str:
|
|
61
|
+
async with wrap_sdk_errors_async(
|
|
62
|
+
"semantic_kernel.search_memory", logger, user_id=self._user_id,
|
|
63
|
+
):
|
|
64
|
+
response = await self._sdk.fetch(
|
|
65
|
+
conversation_id=self._conversation_id,
|
|
66
|
+
user_id=self._user_id,
|
|
67
|
+
customer_id=self._customer_id or None,
|
|
68
|
+
search_query=[query],
|
|
69
|
+
mode="accurate",
|
|
70
|
+
include_conversation_context=False,
|
|
71
|
+
)
|
|
72
|
+
return response.formatted_context or "No relevant memories found."
|
|
73
|
+
|
|
74
|
+
@kernel_function(
|
|
75
|
+
name="store_memory",
|
|
76
|
+
description=(
|
|
77
|
+
"Store an important fact, preference, or event about the user "
|
|
78
|
+
"for future reference."
|
|
79
|
+
),
|
|
80
|
+
)
|
|
81
|
+
async def store_memory(
|
|
82
|
+
self,
|
|
83
|
+
content: Annotated[str, "Information to remember about the user"],
|
|
84
|
+
) -> str:
|
|
85
|
+
async with wrap_sdk_errors_async(
|
|
86
|
+
"semantic_kernel.store_memory", logger, user_id=self._user_id,
|
|
87
|
+
):
|
|
88
|
+
result = await self._sdk.memories.create(
|
|
89
|
+
document=content,
|
|
90
|
+
user_id=self._user_id,
|
|
91
|
+
customer_id=self._customer_id,
|
|
92
|
+
)
|
|
93
|
+
return f"Memory stored (ingestion_id: {result.ingestion_id})"
|