Create and walk a relationship
Connect two documents with a typed relationship, then list the document's neighbors through that relationship. This is the pattern behind every "find all accounts owned by this person" query.
import sasvi
client = sasvi.SVIClient.from_env()
person = client.documents.get(entity_type_name="Person", document_id="<person-id>")
account = client.documents.get(entity_type_name="Account", document_id="<account-id>")
link = person.relationships.create(
account,
relationship="owns",
field_values={"since": "2024-01-15"},
)
print(repr(link))
# RelationshipLinkRecord(...)
The first argument (other) takes a bound Document, a (type, id) tuple, or any
object exposing document-like identifier attributes. Pass relationship= explicitly
when (from_type, to_type) does not pin down a single relationship type; otherwise
the SDK raises DocumentOperationError listing the candidates.
List neighbors
for link in person.relationships.list(relationship_name="owns"):
print(link.to_object_type_name, link.to_object_id, link.field_values)
Filter with relationship_name= to scope the result. Without it you get every link
on the source document.
Walk the graph
For multi-hop traversal, use the Search builder's path helpers rather than walking relationships in Python:
paths = client.search.paths_from(
("Person", "<person-id>"),
types="Account",
)
for path in paths.items:
print(" -> ".join(f"{v.type}:{v.id}" for v in path.vertices))
The path API is far faster than fanning out relationships.list() per hop.
Edit a link
Links are addressed by id. update reads the current link and its ETag, merges your
changes field by field, and sends the result with If-Match, so a concurrent edit
surfaces as DocumentConflictError instead of being overwritten. None leaves a
field alone; clearing a validity bound needs the raw body= form. Validity bounds
only persist on relationship types that define a validity window. On other types the
server drops them silently, which is live-verified behavior.
from datetime import datetime, timezone
from sasvi.documents import RelationshipLinkUpdate
edited = person.relationships.update(
relationship_link_id=link.id,
changes=RelationshipLinkUpdate(
field_values={"since": "2025-01-01"},
valid_to=datetime(2030, 1, 1, tzinfo=timezone.utc),
),
)
print(edited.field_values_dict(), edited.valid_to)
The bound manager refuses a link id that does not touch person. For a link you only
know by id, use client.documents.relationships.update(...).
Audit a link
for version in person.relationships.versions(relationship_link_id=link.id):
print(version.version, version.operation, version.created_by, version.created_at)
snapshot = person.relationships.version(relationship_link_id=link.id, version=1)
if snapshot is not None:
print({value.name: value.value for value in snapshot.values})
for action in person.relationships.actions(
relationship_link_id=link.id, action_type=["RELATIONSHIP_CREATE", "RELATIONSHIP_EDIT"]
):
print(action.action_type, action.action, action.created_at)
versions_all and actions_all walk every page. action(action_id=...) returns the
detail blocks of one entry.
Remove a relationship
person.relationships.remove(relationship_link_id=link.id)
Async
await person.relationships.create_async(account, relationship="owns")
await person.relationships.update_async(
relationship_link_id=link.id, field_values={"since": "2025"}
)
await person.relationships.versions_async(relationship_link_id=link.id)
await person.relationships.remove_async(relationship_link_id=link.id)
Go further
- Documents guide. The
relationshipsmanager. - Search guide. Path queries and graph traversal.