Guide
Use a source predicate to select the initial candidates and .where(...) for
expression-based filtering later in a traversal. Vector and full-text search
prefiltering rank only an exact traversal-defined candidate set.
Common predicates
Values can be literals or typed parameter expressions.
Filter a stream
Vector prefiltering
Vector prefiltering starts with a node or edge traversal, then ranks only the exact members of that stream. Use it when graph membership is a correctness boundary, such as “documents this user may access” or “products reachable from this category.” The execution order is graph traversal → exact candidate membership → vector ranking → top k. The traversal membership is authoritative. Approximate index structures may accelerate ranking, but a result outside the candidate set cannot be returned.Rank a node stream
This request finds projects owned by the current user, ranks that exact set by embedding distance, and returns the top five.This query requires an active three-dimensional cosine vector index on
Project.embedding. Create and activate that index before running the request.VectorSearchEdgesWithin in Go after an edge traversal. Rust
vector_search_with, TypeScript vectorSearchWith, and Python
vector_search_with select the node or edge wire operation from the current stream.
Their literal forms are vector_search and vectorSearch.
Requirements
- Create a compatible vector index for the candidate label and property.
- Match the index dimension exactly.
- Use the same tenant partition value as the index when it is tenant-partitioned.
- Preserve
$distancein a projection before traversing away from a ranked hit. - Bound the candidate traversal when its size can grow without application limits.
Exact membership does not mean the vector engine exhaustively compares every
candidate embedding. It means the final result is checked against the exact traversal
set.
When to search without a prefilter
Use a source vector search when the whole indexed label and optional tenant partition is the intended candidate set. Use vector prefiltering when relationships, permissions, or earlier filters define membership.Full Text Search prefiltering
Full-text search (FTS) prefiltering starts with a node or edge traversal, then ranks only the unique IDs in that stream by BM25 score. Use it when relationships, permissions, or earlier predicates define which records are eligible for text search. The execution order is graph traversal → exact candidate membership → BM25 ranking → top k. Results are identical to an exhaustive BM25 search of the selected tenant partition, intersected with the candidate IDs, followed by deterministic top-k selection. BM25 statistics still come from the full tenant partition.Rank a node stream
This request finds documents the current user can read, ranks that exact set for"graph databases", and returns the top five.
This query requires an active text index on
Document.body. Create and activate that
index before running the request.TextSearchEdgesWithin in Go after an edge traversal. Rust
text_search_with, TypeScript textSearchWith, and Python text_search_with
select the node or edge wire operation from the current stream. Their literal forms
are text_search and textSearch.
Result contract
- Output IDs are a deduplicated subset of the input IDs.
- The result contains at most
min(unique candidates, k)rows. - Rows are ordered by BM25 score descending, then entity ID ascending.
- The selected input row keeps its bindings, path, and sack;
$scoreis attached. - Empty input returns without opening the text index.
- A wrong-kind input or more than 1,000,000 unique candidates is a query error.
- A tenant-partitioned index requires the same tenant value used to build the candidate stream.
When to search without a prefilter
Use a source text search when the whole indexed label and optional tenant partition is the intended candidate set. Do not implement exact FTS filtering as source text search followed by.where(...): excluded high-scoring hits can consume the source
top-k and leave fewer than k eligible results. Build the candidate stream first and
use FTS prefiltering when membership is authoritative.
Next steps
Typed parameters
Move request-specific filter values out of the AST.
Indexes
Back equality and range predicates with an index.
Vector indexes
Create the dimensioned index used for ranking.
Text indexes
Create the BM25 index used for full-text ranking.
Project search results
Preserve ranked hit metadata before continuing a traversal.