A walkthrough, end to end
Seven short steps: load a graph, embed it, retrieve with a vector seed and a graph expansion, and generate an answer that cites what it used. Then the same question put to plain vector RAG, so the difference is visible rather than asserted.
Every call below is checked against the Python SDK's published signatures, version 1.15.0. Two of them are worth knowing before you start: query() takes Cypher text and an optional graph name — there is no parameter binding — and vectors attach to a node id through add_vector(), so nodes are created first and embedded second. The outputs shown are the shape each call returns; the exact ids and scores on your machine will differ.
Set up
Three packages. The engine runs in-process, so there is no server to start and no connection string to get right.
pip install samyama sentence-transformers openai# The engine runs in-process for this walkthrough - nothing to start, nothing# to connect to. Swap embedded() for connect("http://localhost:8080") to run# the same code against a server.
Load the data
A deliberately tiny clinical graph: two drugs, two conditions, three studies — and one edge that matters. The interaction between amiodarone and warfarin is a relationship, not a sentence in a document.
from samyama import SamyamaClientclient = SamyamaClient.embedded()# query() takes Cypher text and an optional graph name. There is no parameter# binding, so values go into the statement itself.client.query("""CREATE (w:Drug {name: 'Warfarin', class: 'anticoagulant'}),(a:Drug {name: 'Amiodarone', class: 'antiarrhythmic'}),(af:Condition {name: 'Atrial fibrillation'}),(vte:Condition {name: 'Venous thromboembolism'}),(s1:Study {id: 'S-1041', title: 'Amiodarone for rhythm control in AF',finding: 'Amiodarone maintained sinus rhythm in 62% at 12 months.'}),(s2:Study {id: 'S-2277', title: 'Warfarin dosing and INR stability',finding: 'Warfarin requires INR monitoring; dose is highly variable.'}),(s3:Study {id: 'S-3310', title: 'CYP2C9 interactions in anticoagulation',finding: 'Amiodarone inhibits CYP2C9, raising warfarin exposure; ''reduce warfarin dose and monitor INR closely.'}),(a)-[:TREATS]->(af),(w)-[:TREATS]->(vte),(s1)-[:ABOUT]->(a),(s2)-[:ABOUT]->(w),(s3)-[:ABOUT]->(w),(s3)-[:ABOUT]->(a),(a)-[:INTERACTS_WITH {effect: 'raises exposure', severity: 'major'}]->(w)""")print(client.status())
Output
ServerStatus(status='healthy', version='1.15.0', nodes=7, edges=8)
Create embeddings
The index is declared with its dimensions and metric, then each study's text is embedded and attached to its node. Any model works — the database indexes whatever you give it.
from sentence_transformers import SentenceTransformermodel = SentenceTransformer("all-MiniLM-L6-v2") # 384 dimensions# One index per (label, property). The metric is part of the index.client.create_vector_index("Study", "embedding", 384, "cosine")# Vectors attach to a node id, so read the ids back first.rows = client.query("MATCH (s:Study) RETURN id(s), s.title, s.finding")for node_id, title, finding in rows.records:vector = model.encode(f"{title}. {finding}").tolist()client.add_vector("Study", "embedding", node_id, vector)print(rows.columns, len(rows))
Output
['id(s)', 's.title', 's.finding'] 3
Retrieve
Two moves. The vector search finds the studies that read like the question; the graph expansion then walks from those studies to the drugs they are about, and picks up the interaction edge between them. The second move is the one plain RAG cannot make.
question = "Can a patient on warfarin be started on amiodarone?"# 1. Vector seed - returns (node_id, score) pairs, nearest firstseeds = client.vector_search("Study", "embedding", model.encode(question).tolist(), k=2)print(seeds)# 2. Graph expansion - from those studies, out to the drugs they are about and# any interaction between them. This is the step plain RAG cannot take.ids = ", ".join(str(node_id) for node_id, _ in seeds)context = client.query(f"""MATCH (s:Study) WHERE id(s) IN [{ids}]MATCH (s)-[:ABOUT]->(d:Drug)OPTIONAL MATCH (d)-[i:INTERACTS_WITH]-(other:Drug)RETURN s.id, s.finding, d.name, type(i), i.severity, other.name""")for row in context.records:print(row)
Output
[(4, 0.6891), (5, 0.5402)] ['S-2277', 'Warfarin requires INR monitoring; dose is highly variable.', 'Warfarin', None, None, None] ['S-3310', 'Amiodarone inhibits CYP2C9, raising warfarin exposure; reduce warfarin dose and monitor INR closely.', 'Warfarin', 'INTERACTS_WITH', 'major', 'Amiodarone'] ['S-3310', 'Amiodarone inhibits CYP2C9, raising warfarin exposure; reduce warfarin dose and monitor INR closely.', 'Amiodarone', 'INTERACTS_WITH', 'major', 'Warfarin']
Notice what the expansion added. The vector search returned two studies; the traversal returned a major-severity interaction that neither study's text states in those words.
Generate
The retrieved rows become the prompt. Graph facts are labelled as such, so the model can cite them separately from the document findings, and it is told to refuse when the facts do not support an answer.
from openai import OpenAIllm = OpenAI()facts = []for study_id, finding, drug, rel, severity, other in context.records:facts.append(f"[{study_id}] {drug}: {finding}")if rel:facts.append(f"[graph] {drug} {rel} {other} (severity: {severity})")prompt = ("Answer using only the facts below. Cite the study id or [graph] for each ""claim. If the facts do not support an answer, say so.\n\n"+ "\n".join(dict.fromkeys(facts)) # de-duplicate, keep order+ f"\n\nQuestion: {question}")answer = llm.chat.completions.create(model="gpt-4o-mini",messages=[{"role": "user", "content": prompt}],).choices[0].message.contentprint(answer)
The answer and its sources
Every claim carries the study it came from, or [graph] for a fact that came from a relationship rather than a document.
Output
Not without adjusting the warfarin dose. Amiodarone inhibits CYP2C9, which raises warfarin exposure, and the interaction is recorded as major severity [S-3310] [graph]. Warfarin already requires INR monitoring because its dose is highly variable [S-2277], so starting amiodarone means reducing the warfarin dose and monitoring INR closely [S-3310].
Because the citations are node properties rather than prose, they can be resolved back to the graph:
MATCH (s:Study) WHERE s.id IN ['S-2277', 'S-3310']MATCH (s)-[:ABOUT]->(d:Drug)RETURN s.id AS source, s.title AS title, collect(d.name) AS drugs
Output
['source', 'title', 'drugs'] ['S-2277', 'Warfarin dosing and INR stability', ['Warfarin']] ['S-3310', 'CYP2C9 interactions in anticoagulation', ['Warfarin', 'Amiodarone']]
Against plain vector RAG
The same question, the same embeddings, the same model — with the graph expansion removed. Only step 3 changes.
Vector RAG only
Retrieves S-2277 and S-3310 by similarity and stops. S-3310 does mention the interaction, so the answer is partly right — but nothing tells the model the severity, and if the top-k had returned S-1041 and S-2277 instead, the interaction would be absent altogether.
retrieved: 2 chunks
relationships: 0
severity available: no
GraphRAG
Starts from the same two studies, then follows ABOUT to the drugs and INTERACTS_WITH between them. The severity is a property on the edge, so it reaches the prompt whichever studies the vector search happened to return.
retrieved: 2 chunks + 3 rows
relationships: 1 (major)
severity available: yes
The honest version of the claim: GraphRAG did not rescue a wrong answer here — it made a right answer reproducible. Plain retrieval got close because one chunk happened to contain the interaction. The graph puts that fact on an edge, where it is found by traversal rather than by luck in the ranking. Our own controlled study found the same pattern: grounding pays off on knowledge the model does not already hold, not on facts it absorbed in training.

