← Home

Implementing HNSW in RDF

Most databases treat vectors and graphs as separate systems. sutraDB stores vector embeddings as typed RDF literals (sutra:f32vec) and exposes HNSW neighbor connections as virtual triples — making the vector index queryable by the same SPARQL engine that traverses relationships.

Data triples: regular RDF relationships (:discusses, :author).
Vector triples: embeddings stored as typed literals (:hasEmbedding "..."^^sutra:f32vec).
HNSW triples: neighbor edges generated on-the-fly from the HNSW index (sutra:hnswNeighbor).
:paper_42 :hasEmbedding "0.23 -0.11 0.87 ..."^^sutra:f32vec .

SELECT ?similar ?topic
WHERE {
  :paper_42 sutra:hnswNeighbor+ ?similar .
  ?similar :discusses ?topic .
}
The HNSW index is the 4th index type alongside SPO/POS/OSP. SPARQL property paths can traverse sutra:hnswNeighbor+ just like :hasFather+. The query planner decides whether to use HNSW or triple indexes based on cost — no separate vector database API needed.