forked from vektori-ai/vektori
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart_postgres.py
More file actions
59 lines (47 loc) · 1.72 KB
/
Copy pathquickstart_postgres.py
File metadata and controls
59 lines (47 loc) · 1.72 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
"""
Vektori Quickstart — PostgreSQL backend.
Prerequisites:
docker compose up -d
pip install 'vektori[postgres]'
export OPENAI_API_KEY=sk-...
"""
import asyncio
import os
from vektori import Vektori
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://vektori:vektori@localhost:5432/vektori")
async def main():
async with Vektori(
database_url=DATABASE_URL,
embedding_model="openai:text-embedding-3-small",
extraction_model="openai:gpt-4o-mini",
) as v:
print("Adding memories...")
result = await v.add(
messages=[
{"role": "user", "content": "I only use WhatsApp, please don't email me."},
{"role": "assistant", "content": "Got it, WhatsApp only."},
{"role": "user", "content": "I can pay ₹45,000 by end of Friday."},
],
session_id="call-001",
user_id="user-123",
)
print(f"Stored: {result}")
await asyncio.sleep(6) # wait for async extraction
# L2: full story — facts + episodes + source sentences + session context
results = await v.search(
query="What are the payment details for this user?",
user_id="user-123",
depth="l2",
context_window=3,
)
print("\nFacts:")
for f in results.get("facts", []):
print(f" [{f.get('score', 0):.3f}] {f['text']}")
print("\nEpisodes:")
for ep in results.get("episodes", []):
print(f" {ep['text']}")
print("\nSource sentences:")
for s in results.get("sentences", []):
print(f" [{s['session_id']}] {s['text']}")
if __name__ == "__main__":
asyncio.run(main())