Skip to content

Reference

db.neighbors

List the outgoing links of a record.

db.neighbors(id: str, type: str | None = None) -> list[tuple[str, str]]
  • id : str An existing record.

  • type : str, optional Only links of this type. Default None returns every type.

(link_type, target id) tuples, sorted by type and then target.

  • ValueError The id is unknown or type is not a valid link type name.
import srvdb
db = srvdb.create("./vectors", dimension=128)
vs = [[float(i == j) for j in range(128)] for i in range(3)]
db.add(["a", "b", "c"], vs, ["{}"] * 3)
db.link("a", "cites", "b")
db.link("a", "about", "c")
print(db.neighbors("a"))
# [('about', 'c'), ('cites', 'b')]
print(db.neighbors("a", type="cites"))
# [('cites', 'b')]