---
title: "Graph and vector | SurrealDB"
description: "Graph relationships and vector search in one engine. Traverse edges with arrow syntax and run HNSW similarity search in a single SurrealQL query."
url: https://surrealdb.com/surrealdb/graph
---

GRAPH AND VECTOR

# Graph and vector, one query

Model relationships as native graph edges and search meaning with HNSW vector indexes - in the same database, over the same records. Traverse connections and rank by similarity in a single SurrealQL statement, with structured filters narrowing the set first.

[Read the docs](https://surrealdb.com/docs/reference/query-language/statements/relate) [Start free with SurrealDB](https://studio.surrealdb.com/current/instances/deploy)

1. ![Babcock](https://surrealdb.com/assets/static/babcock.lo4rnVg1.svg)
2. ![ING](https://surrealdb.com/assets/static/ing.X3I6S3_V.svg)
3. ![British Airways](https://surrealdb.com/assets/static/british-airways.KEsZiwV-.svg)
4. ![Nvidia](https://surrealdb.com/assets/static/nvidia.DaIEuMil.svg)
5. ![Apple](https://surrealdb.com/assets/static/apple.D5pq4flY.svg)
6. ![SpaceX](https://surrealdb.com/assets/static/spacex.CQJEk-IL.svg)
7. ![Samsung](https://surrealdb.com/assets/static/samsung.CH-vQgnb.svg)
8. ![adidas](https://surrealdb.com/assets/static/adidas.DdTC5qhk.svg)
9. ![Tencent](https://surrealdb.com/assets/static/tencent.paQmLxyy.svg)
10. ![Alibaba](https://surrealdb.com/assets/static/alibaba.B16idgfM.svg)
11. ![PolyAI](https://surrealdb.com/assets/static/poly-ai.c3w_fAg6.svg)
12. ![Later](https://surrealdb.com/assets/static/later.Ds736jFO.svg)
13. ![Verizon](https://surrealdb.com/assets/static/verizon.BI7CajdX.svg)
14. ![Liberty Mutual](https://surrealdb.com/assets/static/liberty-mutual.B7qOU1pd.svg)
15. ![Walmart](https://surrealdb.com/assets/static/walmart.BjDg_Sr8.svg)
16. ![Carrier](https://surrealdb.com/assets/static/carrier.D21gC6NX.svg)
17. ![Saks Fifth Avenue](https://surrealdb.com/assets/static/saks-fifth-avenue.COIDpLSb.svg)
18. ![San Francisco Compute Company](https://surrealdb.com/assets/static/sfcc.B7jlImq4.svg)
19. ![Shield AI](https://surrealdb.com/assets/static/shield-ai.pINZ0KJr.svg)
20. ![Wix](https://surrealdb.com/assets/static/wix.DvHhmoBi.svg)

01 |CONNECTED DATA

## Relationships and similarity, together

Edges are full documents you traverse with arrow syntax; vectors are an index on the same table. Because both live in one engine, one query can walk the graph and rank by meaning.

GRAPH RELATIONSHIPS

## Edges are records you traverse

RELATE connects two records through an edge that carries its own fields. Arrow syntax walks those connections without a join.

```
RELATE customer:alice->purchased->product:widget_pro    SET quantity = 2, date = time::now(), source = 'web';SELECT ->purchased[WHERE date > time::now() - 30d]->product.name    FROM customer:alice;
```

VECTOR SEARCH

## Similarity on the same records

Define an HNSW index on a field of embeddings, then rank by distance - with a structured WHERE clause scoping the candidates before the vector search runs.

```
DEFINE INDEX product_embedding ON product    FIELDS embedding HNSW DIMENSION 1536 DIST COSINE;SELECT id, name, vector::distance::knn() AS distance    FROM product    WHERE category = 'tools'        AND embedding <|10,40|> $query_embedding    ORDER BY distance;
```

## A graph database and a vector database in one

Native relationships, approximate-nearest-neighbour search, and full-text ranking compose in a single query language over a single copy of your data.

### [Native graph model](https://surrealdb.com/docs/reference/query-language/statements/relate)

Nodes, edges, and properties as first-class records, traversed with arrow syntax to any depth.

Learn more

### [Recursive traversal](https://surrealdb.com/surrealdb/features#data-model)

Walk chains and dependency trees with recursive graph queries, filtering edges as you go.

Learn more

### [HNSW vector index](https://surrealdb.com/surrealdb/features#indexing-and-search)

Approximate-nearest-neighbour search with cosine, euclidean, and manhattan distance over your embeddings.

Learn more

### [Hybrid search](https://surrealdb.com/surrealdb/features#indexing-and-search)

Combine full-text BM25 and vector similarity in one query with reciprocal rank fusion.

Learn more

### [Scope first, rank second](https://surrealdb.com/surrealdb/deep-dive)

A structured filter narrows the candidate set before the vector search, so similarity runs on the rows that matter.

Learn more

### [One copy of the data](https://surrealdb.com/surrealdb/deep-dive)

Graph edges, vectors, and documents share the same records - no syncing a vector store to a graph store.

Learn more

02 |ONE ENGINE

## No vector store bolted to a graph store

The usual stack stitches a graph database, a vector database, and a document store together, then syncs them. SurrealDB makes all three the same records, queried the same way.

### One query, both models

Traverse relationships and rank by similarity in a single statement, instead of querying two systems and merging results in application code.

### No sync to drift

There is no pipeline copying rows into a separate vector index that can fall behind or disagree with the source.

### Lower latency

Filter, traverse, and rank happen in one engine, in one pass, without a network hop between stores.

## Keep exploring

### [RELATE documentation](https://surrealdb.com/docs/reference/query-language/statements/relate)

Graph edges, arrow syntax, and traversal in full.

Explore

### [Technical deep-dive](https://surrealdb.com/surrealdb/deep-dive)

How graph and vector compose in the query engine.

Explore

### [All features](https://surrealdb.com/surrealdb/features#indexing-and-search)

The complete data-model, indexing, and search set.

Explore

GET STARTED

## Query relationships and meaning together

Traverse the graph and rank by vector similarity in one SurrealQL query, over one copy of your data.

![Samsung](https://surrealdb.com/assets/static/4c58b81e7b3c9466.C_Hv0eml.svg)![NVIDIA](https://surrealdb.com/assets/static/nvidia.DaIEuMil.svg)![Apple](https://surrealdb.com/assets/static/f7dc2519e0d212bc.Cn8MYAK7.svg)![Verizon](https://surrealdb.com/assets/static/18b99996c689000f.B5PQ-nI9.svg)![Tencent](https://surrealdb.com/assets/static/401d8346058682c8.DqM87mst.svg)

SOC 2 Type 2

GDPR

Cyber Essentials Plus

ISO 27001

[Read the docs](https://surrealdb.com/docs/reference/query-language/statements/relate) [Start free with SurrealDB](https://studio.surrealdb.com/current/instances/deploy)

```json
{"@context":"https://schema.org","@type":"Organization","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is the unified data layer for AI. A multi-model database for documents, graphs, vectors, and time-series.","foundingDate":"2022","legalName":"SurrealDB Ltd","identifier":{"@type":"PropertyValue","propertyID":"GB-COH","value":"13615201"},"address":{"@type":"PostalAddress","streetAddress":"3rd Floor, 1 Ashley Road","addressLocality":"Altrincham","addressRegion":"Cheshire","postalCode":"WA14 2DT","addressCountry":"GB"},"contactPoint":[{"@type":"ContactPoint","contactType":"customer support","email":"support@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"sales","email":"info@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"security","email":"security@surrealdb.com","url":"https://surrealdb.com/.well-known/security.txt","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"legal","email":"legal@surrealdb.com","url":"https://surrealdb.com/legal","availableLanguage":"English"}],"hasCertification":[{"@type":"Certification","name":"SOC 2 Type 2"},{"@type":"Certification","name":"GDPR"},{"@type":"Certification","name":"Cyber Essentials Plus"},{"@type":"Certification","name":"ISO 27001"}],"owns":[{"@type":"SoftwareApplication","name":"SurrealDB","url":"https://surrealdb.com/surrealdb"},{"@type":"SoftwareApplication","name":"Agent Memory","url":"https://surrealdb.com/agent-memory"}],"knowsAbout":["multi-model databases","document databases","graph databases","vector search","time-series databases","SurrealQL","Agent Memory","real-time databases","embedded databases","context layer","graph ontology","distributed database","knowledge graphs","distributed transaction protocols","highly-scalable databases"],"sameAs":["https://www.wikidata.org/wiki/Q124316308","https://github.com/surrealdb/surrealdb","https://twitter.com/surrealdb","https://www.youtube.com/@surrealdb","https://www.linkedin.com/company/surrealdb","https://discord.gg/surrealdb","https://www.reddit.com/r/surrealdb","https://www.instagram.com/surrealdb","https://medium.com/surrealdb","https://dev.to/surrealdb"]}
```

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://surrealdb.com"},{"@type":"ListItem","position":2,"name":"SurrealDB","item":"https://surrealdb.com/surrealdb"},{"@type":"ListItem","position":3,"name":"Graph","item":"https://surrealdb.com/surrealdb/graph"}]}
```
