Tutorial: Vector Search

Embeddings are first-class node properties in ArcFlow — stored in the world model alongside confidence scores and relationships, searchable with the same GQL used for everything else.

Overview#

ArcFlow includes a built-in vector index. You can:

  1. Store embeddings as node properties
  2. Create a vector index
  3. Search for nearest neighbors by similarity

No external vector database needed.

1. Store embeddings#

import { openInMemory } from '@ozinc/arcflow'
 
const db = openInMemory()
 
// Create nodes with embedding properties
db.mutate("CREATE (d:Document {title: 'AI Introduction', embedding: '[0.1, 0.2, 0.3, 0.4, 0.5]'})")
db.mutate("CREATE (d:Document {title: 'Machine Learning', embedding: '[0.15, 0.22, 0.28, 0.42, 0.48]'})")
db.mutate("CREATE (d:Document {title: 'Database Systems', embedding: '[0.8, 0.1, 0.05, 0.02, 0.03]'})")

2. Create a vector index#

db.mutate(
  "CREATE VECTOR INDEX doc_search FOR (n:Document) ON (n.embedding) OPTIONS {dimensions: 5, similarity: 'cosine'}"
)

Options:

  • dimensions — must match your embedding size (e.g., 1536, 768, or 384 depending on your model)
  • similarity — 'cosine' (recommended) or 'euclidean'

3. Search by similarity#

const queryVector = [0.12, 0.21, 0.29, 0.41, 0.49]  // From your embedding model
 
const results = db.query(
  "CALL algo.vectorSearch('doc_search', $vector, $k)",
  { vector: JSON.stringify(queryVector), k: 5 }
)
 
for (const row of results.rows) {
  console.log(row.get('title'), row.get('score'))
}
// "Machine Learning" 0.99
// "AI Introduction" 0.97
// "Database Systems" 0.42

4. Combine vector search with graph traversal#

The real power: use vector similarity to find a starting point, then traverse the graph for context.

// Find similar documents, then get their authors and related topics
const similar = db.query(
  "CALL algo.vectorSearch('doc_search', $vector, 3)",
  { vector: JSON.stringify(queryVector) }
)
 
for (const row of similar.rows) {
  const docTitle = row.get('title')
 
  // Traverse from each result
  const context = db.query(
    "MATCH (d:Document {title: $title})-[:AUTHORED_BY]->(a:Person) RETURN a.name",
    { title: String(docTitle) }
  )
  console.log(`${docTitle} by ${context.rows.map(r => r.get('name')).join(', ')}`)
}

5. GraphRAG pattern#

Use the built-in GraphRAG procedure for retrieval-augmented generation:

const context = db.query("CALL algo.graphRAG()")
// Returns graph context optimized for LLM consumption

Full-text search alternative#

For keyword-based search (no embeddings needed):

// Create full-text index
db.mutate("CREATE FULLTEXT INDEX doc_text FOR (n:Document) ON (n.title)")
 
// Search with BM25 scoring
const results = db.query("CALL db.index.fulltext.queryNodes('doc_text', 'machine learning')")

Combine vector similarity with full-text search:

const results = db.query(
  "CALL algo.hybridSearch()",
  // Combines vector and keyword signals
)

See Also#

  • Vector Search — vector index setup, hybrid search, and configuration reference
  • Trusted RAG — confidence-filtered retrieval built on vector + graph search
  • Graph Algorithms — combine vector search with PageRank for importance-weighted results
  • GPU Acceleration — GPU-accelerated ANN search at scale
Try it
Open ↗
Loading engine…