-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart_sqlite.py
More file actions
69 lines (55 loc) · 1.9 KB
/
Copy pathquickstart_sqlite.py
File metadata and controls
69 lines (55 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Smallest end-to-end example: persist a session to SQLite, then search it back.
Run:
pip install "adk-database-memory[sqlite]"
python examples/quickstart_sqlite.py
"""
from __future__ import annotations
import asyncio
from google.adk.events.event import Event
from google.adk.sessions.session import Session
from google.genai import types
from adk_database_memory import DatabaseMemoryService
DB_URL = "sqlite+aiosqlite:///quickstart_memory.db"
APP_NAME = "quickstart_app"
USER_ID = "alice"
def make_session() -> Session:
return Session(
app_name=APP_NAME,
user_id=USER_ID,
id="session-001",
last_update_time=1.0,
events=[
Event(
id="e1",
invocation_id="inv-1",
author="user",
timestamp=1.0,
content=types.Content(
parts=[types.Part(text="We agreed the launch date is November 15.")]
),
),
Event(
id="e2",
invocation_id="inv-2",
author="model",
timestamp=2.0,
content=types.Content(
parts=[types.Part(text="Confirmed: launch on November 15.")]
),
),
],
)
async def main() -> None:
async with DatabaseMemoryService(DB_URL) as memory:
await memory.add_session_to_memory(make_session())
result = await memory.search_memory(
app_name=APP_NAME,
user_id=USER_ID,
query="when is the launch date?",
)
print(f"Found {len(result.memories)} matching memory entries:")
for entry in result.memories:
text = entry.content.parts[0].text if entry.content and entry.content.parts else ""
print(f" [{entry.author} @ {entry.timestamp}] {text}")
if __name__ == "__main__":
asyncio.run(main())