-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquickstart.py
More file actions
78 lines (57 loc) · 2.36 KB
/
quickstart.py
File metadata and controls
78 lines (57 loc) · 2.36 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
70
71
72
73
74
75
76
77
78
"""Synaptic Memory — 5-minute quickstart.
Copy-paste this file, run it, and you have a working knowledge graph with
hybrid (lexical + vector + graph) retrieval over a small product catalog.
Prerequisites
-------------
Install with the recommended extras (one command)::
pip install "synaptic-memory[sqlite,korean,vector]"
Or with uv::
uv pip install "synaptic-memory[sqlite,korean,vector]"
Run::
python examples/quickstart.py
What it does
------------
1. Ingests ``examples/data/products.csv`` (10 rows) into a SQLite-backed
knowledge graph at ``quickstart.db``.
2. Runs three searches showing hybrid retrieval — FTS + usearch HNSW
vector search + graph-aware reranking.
3. Prints the top result for each query with its activation score.
No LLM is called at any point — indexing is free, search is local.
"""
from __future__ import annotations
import asyncio
from pathlib import Path
from synaptic import SynapticGraph
DATA_PATH = Path(__file__).parent / "data" / "products.csv"
DB_PATH = "quickstart.db"
async def main() -> None:
# Build the graph. Auto-detects CSV, generates a DomainProfile,
# ingests each row as an ENTITY node, and indexes it.
graph = await SynapticGraph.from_data(str(DATA_PATH), db=DB_PATH)
try:
stats = await graph.stats()
print(f"Ingested: {stats.get('total_nodes', 0)} nodes\n")
queries = [
"laptop with long battery",
"spicy Korean noodles",
"facial skincare mask",
]
for query in queries:
print(f"Query: {query!r}")
# engine="evidence" selects the 3rd-gen retrieval pipeline
# (BM25 + HNSW + PPR + cross-encoder + MMR). Default flips
# to "evidence" in v0.16.0.
result = await graph.search(query, limit=3, engine="evidence")
for i, activated in enumerate(result.nodes[:3], 1):
node = activated.node
name = node.properties.get("name", node.title or node.id)
print(f" {i}. {name:<30} score={activated.activation:.3f}")
print()
finally:
# Close the backend connection cleanly so aiosqlite's worker
# thread exits before the event loop does.
close = getattr(graph._backend, "close", None)
if close is not None:
await close()
if __name__ == "__main__":
asyncio.run(main())