High-performance vector similarity search integrated into GSQL queries.
Vector Search
TigerGraph functions as a multi-modal database, allowing you to store and index high-dimensional vectors alongside your graph data. This is a critical feature for AI applications like Retrieval-Augmented Generation (RAG) and recommendation systems.
1. Schema Configuration
Vector attributes are added to existing vertex types via a schema change job.
gsqlterminalCREATE GLOBAL SCHEMA_CHANGE JOB add_vector { ALTER VERTEX User ADD VECTOR ATTRIBUTE embedding( DIMENSION=1536, METRIC="COSINE", INDEXTYPE="HNSW" ); } RUN GLOBAL SCHEMA_CHANGE JOB add_vector
Key Parameters
- DIMENSION: Vector length (e.g., 1536 for OpenAI embeddings).
- METRIC: Similarity measure (
"COSINE","L2", or"IP"). - INDEXTYPE: The algorithm used for indexing (
"HNSW"is the default).
2. Loading Vectors
You can load vectors in bulk using a standard loading job with the SPLIT function.
gsqlterminalLOAD file_object TO VECTOR ATTRIBUTE embedding ON VERTEX User VALUES ($0, SPLIT($1, ",")) USING SEPARATOR="|";
3. Querying with vectorSearch()
The vectorSearch function is used within a GSQL query to find the top-K similar vertices.
gsqlterminalCREATE QUERY find_similar_users (LIST<FLOAT> query_vec) SYNTAX v3 { MapAccum<Vertex, Float> @@distances; // Find top 10 users similar to the input vector result = vectorSearch({User.embedding}, query_vec, 10, {distance_map: @@distances}); PRINT result; }
4. Hybrid Graph+Vector Search
Because vector search is just another function in GSQL, you can combine it with graph traversals:
- Perform a Vector Search to find a starting set of vertices.
- Traverse the Graph from those vertices to find related entities or calculate PageRank.
[!IMPORTANT] Indexing Lag: The HNSW index is updated incrementally. New vectors might not be searchable until the indexing process (rebuild) is complete. Monitor status via
GET /restpp/vector/status.
On this page
TigerGraph Book
v1.0 Curated