Tools: What if SQL could search by meaning? Meet VelesQL (2026)
The problem with multi-model queries
Creating collections with DDL
Inserting data with SQL syntax
Vector search with NEAR
Combining vector search with metadata filters
Advanced WHERE: IN, BETWEEN, ILIKE, IS NULL
Full-text search with MATCH
Hybrid search: NEAR + MATCH
LET bindings: named scores
Graph queries with MATCH patterns
Cypher-style MATCH in WHERE
Combining graph + metadata + vector search
Edge queries and properties
Search quality tuning with WITH
UPDATE, DELETE, and other DML
Set operations: UNION, INTERSECT, EXCEPT
DISTINCT: deduplicate results
Temporal queries
Query introspection with EXPLAIN
Index management
Agent Memory collections
VelesQL vs. the alternatives
The full VelesQL feature set at a glance
Getting started You know SQL. You have been writing SELECT, WHERE, and JOIN for years. But the moment you need to search by meaning, traverse a knowledge graph, or rank results by relevance, SQL cannot help you. You reach for a proprietary API, a different client, a different mental model. What if you did not have to? VelesQL is a query language that starts where SQL stops. It keeps the syntax you already know and adds three things SQL never had: vector similarity search (NEAR), graph pattern matching (MATCH), and full-text BM25 ranking. One language. One query. One result set. This article walks through VelesQL from the ground up, with working Python code you can run right now. A typical AI application needs three types of search: Today, most developers use three separate systems for this. A vector database for embeddings, a graph database for relationships, and Elasticsearch or similar for text. That means three clients, three query languages, three result formats, and a stitching layer to merge everything. VelesQL replaces this with a single query interface: That is it. No Docker, no server process, no API key. VelesDB runs as a library. The database is a folder on disk. VelesQL supports full DDL. You create collections the same way you create tables in SQL: You can also describe a collection to see its configuration: No more collection.upsert() calls with dictionaries. Just INSERT: Multi-row INSERT is also supported: Here is where VelesQL diverges from SQL. The NEAR keyword performs approximate nearest neighbor search on dense vectors: The similarity() function returns the pre-computed search score. You can use it in SELECT, ORDER BY, and even in LET bindings (more on that below). Just add AND conditions like you would in SQL: Only tutorials are returned. The metadata filter runs alongside the vector search, not as a post-filter. VelesQL supports the full range of SQL filtering operators. If you know SQL, you already know how to filter in VelesQL: ILIKE is particularly useful: it matches case-insensitively, so '%ai%' finds both "AI-Powered Search" and "ai portfolio optimizer". LIKE does the same but case-sensitive. The MATCH keyword performs BM25 full-text search: When you combine NEAR and MATCH, VelesQL automatically fuses the results using Reciprocal Rank Fusion (RRF): You can also control the fusion strategy explicitly: Four fusion strategies are available: VelesQL 3.2 introduced LET bindings. Define a score expression once, use it everywhere: LET bindings shine in hybrid queries where you want to weight multiple score components: Bindings can reference earlier bindings, so you can build complex scoring pipelines: VelesQL borrows Cypher-style graph patterns. Here is a complete example that builds a knowledge graph and queries it: Now query the graph using MATCH patterns inside a WHERE clause: This is where VelesQL shines. A single query that walks a graph, filters by metadata, and ranks by vector similarity: Query edges directly with SELECT EDGES: Edges can also carry properties: Every vector search query can be fine-tuned with a WITH clause: Five quality presets are available: VelesQL supports the full CRUD lifecycle: Combine results from multiple queries, just like in SQL: N-ary chaining works too: A UNION B UNION C evaluates left to right. Filter by time without converting timestamps manually: NOW() returns the current Unix timestamp. INTERVAL supports seconds, minutes, hours, days, weeks, and months. Before optimizing, understand what the query planner is doing: Create secondary indexes on metadata fields for faster filtering: If you use VelesDB's Agent Memory SDK, the three memory subsystems (semantic, episodic, procedural) are queryable via VelesQL: The same works for _episodic_memory (with timestamp filtering) and _procedural_memory (with confidence sorting). The point is not that VelesQL replaces SQL everywhere. It fills a gap: the space where you need vector search, graph queries, and text ranking in one place, without running three separate systems. VelesDB is still young. JOIN is fully supported for INNER JOIN, but LEFT/RIGHT/FULL JOIN are parsed and produce explicit runtime errors rather than silent failures. MATCH in hybrid mode boosts rather than strictly filters. These are documented tradeoffs, not bugs, and the query planner tells you exactly what it will do via EXPLAIN. The complete specification is on GitHub. If you find the project useful, a star on the repo helps other developers discover it. We are actively looking for partners and contributors who have use cases for hybrid search, check velesdb.com for details. What query would you write first with VelesQL? I am curious whether the hybrid NEAR + MATCH pattern or the graph traversal feels more useful to your projects. Drop a comment below. Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse
1. Vector search → "Find documents similar to this embedding"
2. Graph traversal → "Walk relationships between entities"
3. Full-text search → "Rank documents containing these keywords"
1. Vector search → "Find documents similar to this embedding"
2. Graph traversal → "Walk relationships between entities"
3. Full-text search → "Rank documents containing these keywords"
1. Vector search → "Find documents similar to this embedding"
2. Graph traversal → "Walk relationships between entities"
3. Full-text search → "Rank documents containing these keywords"
Your app → Pinecone client (proprietary API) → Neo4j client (Cypher) → Elasticsearch (JSON DSL) → custom code to merge results
Your app → Pinecone client (proprietary API) → Neo4j client (Cypher) → Elasticsearch (JSON DSL) → custom code to merge results
Your app → Pinecone client (proprietary API) → Neo4j client (Cypher) → Elasticsearch (JSON DSL) → custom code to merge results
Your app → VelesDB + VelesQL (one language, one result set)
Your app → VelesDB + VelesQL (one language, one result set)
Your app → VelesDB + VelesQL (one language, one result set)
pip install velesdb numpy
pip install velesdb numpy
pip install velesdb numpy
import velesdb
import numpy as np db = velesdb.Database("./velesql_demo")
import velesdb
import numpy as np db = velesdb.Database("./velesql_demo")
import velesdb
import numpy as np db = velesdb.Database("./velesql_demo")
# Create a vector collection
db.execute_query("CREATE COLLECTION articles (dimension = 384, metric = 'cosine')") # Create a graph collection with schema
db.execute_query(""" CREATE GRAPH COLLECTION knowledge (dimension = 384, metric = 'cosine') SCHEMALESS
""") # Inspect what we have
results = db.execute_query("SHOW COLLECTIONS")
for r in results: print(f" {r['payload']['name']} ({r['payload']['type']})")
# Create a vector collection
db.execute_query("CREATE COLLECTION articles (dimension = 384, metric = 'cosine')") # Create a graph collection with schema
db.execute_query(""" CREATE GRAPH COLLECTION knowledge (dimension = 384, metric = 'cosine') SCHEMALESS
""") # Inspect what we have
results = db.execute_query("SHOW COLLECTIONS")
for r in results: print(f" {r['payload']['name']} ({r['payload']['type']})")
# Create a vector collection
db.execute_query("CREATE COLLECTION articles (dimension = 384, metric = 'cosine')") # Create a graph collection with schema
db.execute_query(""" CREATE GRAPH COLLECTION knowledge (dimension = 384, metric = 'cosine') SCHEMALESS
""") # Inspect what we have
results = db.execute_query("SHOW COLLECTIONS")
for r in results: print(f" {r['payload']['name']} ({r['payload']['type']})")
articles (vector) knowledge (graph)
articles (vector) knowledge (graph)
articles (vector) knowledge (graph)
info = db.execute_query("DESCRIBE COLLECTION articles")
print(info[0]['payload'])
# {'name': 'articles', 'type': 'vector', 'dimension': 384, 'metric': 'Cosine', 'point_count': 0}
info = db.execute_query("DESCRIBE COLLECTION articles")
print(info[0]['payload'])
# {'name': 'articles', 'type': 'vector', 'dimension': 384, 'metric': 'Cosine', 'point_count': 0}
info = db.execute_query("DESCRIBE COLLECTION articles")
print(info[0]['payload'])
# {'name': 'articles', 'type': 'vector', 'dimension': 384, 'metric': 'Cosine', 'point_count': 0}
def make_vector(): """Generate a random 384-dim vector for demonstration.""" v = np.random.rand(384).astype(np.float32) return (v / np.linalg.norm(v)).tolist() np.random.seed(42) documents = [ (1, "Vector databases for AI applications", "tutorial"), (2, "Graph neural networks explained", "guide"), (3, "Building RAG pipelines with Python", "tutorial"), (4, "Knowledge graphs in healthcare", "research"), (5, "Hybrid search strategies for production", "tutorial"),
] for doc_id, title, category in documents: v = make_vector() db.execute_query( "INSERT INTO articles (id, vector, title, category) VALUES ($id, $v, $title, $cat)", {"id": doc_id, "v": v, "title": title, "cat": category} ) print(f"Inserted {len(documents)} documents")
def make_vector(): """Generate a random 384-dim vector for demonstration.""" v = np.random.rand(384).astype(np.float32) return (v / np.linalg.norm(v)).tolist() np.random.seed(42) documents = [ (1, "Vector databases for AI applications", "tutorial"), (2, "Graph neural networks explained", "guide"), (3, "Building RAG pipelines with Python", "tutorial"), (4, "Knowledge graphs in healthcare", "research"), (5, "Hybrid search strategies for production", "tutorial"),
] for doc_id, title, category in documents: v = make_vector() db.execute_query( "INSERT INTO articles (id, vector, title, category) VALUES ($id, $v, $title, $cat)", {"id": doc_id, "v": v, "title": title, "cat": category} ) print(f"Inserted {len(documents)} documents")
def make_vector(): """Generate a random 384-dim vector for demonstration.""" v = np.random.rand(384).astype(np.float32) return (v / np.linalg.norm(v)).tolist() np.random.seed(42) documents = [ (1, "Vector databases for AI applications", "tutorial"), (2, "Graph neural networks explained", "guide"), (3, "Building RAG pipelines with Python", "tutorial"), (4, "Knowledge graphs in healthcare", "research"), (5, "Hybrid search strategies for production", "tutorial"),
] for doc_id, title, category in documents: v = make_vector() db.execute_query( "INSERT INTO articles (id, vector, title, category) VALUES ($id, $v, $title, $cat)", {"id": doc_id, "v": v, "title": title, "cat": category} ) print(f"Inserted {len(documents)} documents")
db.execute_query( """INSERT INTO articles (id, vector, title, category) VALUES ($id1, $v1, 'Sparse embeddings 101', 'tutorial'), ($id2, $v2, 'Local-first AI architectures', 'guide')""", {"id1": 6, "v1": make_vector(), "id2": 7, "v2": make_vector()}
)
db.execute_query( """INSERT INTO articles (id, vector, title, category) VALUES ($id1, $v1, 'Sparse embeddings 101', 'tutorial'), ($id2, $v2, 'Local-first AI architectures', 'guide')""", {"id1": 6, "v1": make_vector(), "id2": 7, "v2": make_vector()}
)
db.execute_query( """INSERT INTO articles (id, vector, title, category) VALUES ($id1, $v1, 'Sparse embeddings 101', 'tutorial'), ($id2, $v2, 'Local-first AI architectures', 'guide')""", {"id1": 6, "v1": make_vector(), "id2": 7, "v2": make_vector()}
)
query_vector = make_vector() results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q ORDER BY similarity() DESC LIMIT 3""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
query_vector = make_vector() results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q ORDER BY similarity() DESC LIMIT 3""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
query_vector = make_vector() results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q ORDER BY similarity() DESC LIMIT 3""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
[0.821] Vector databases for AI applications [0.779] Building RAG pipelines with Python [0.752] Hybrid search strategies for production
[0.821] Vector databases for AI applications [0.779] Building RAG pipelines with Python [0.752] Hybrid search strategies for production
[0.821] Vector databases for AI applications [0.779] Building RAG pipelines with Python [0.752] Hybrid search strategies for production
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND category = 'tutorial' ORDER BY similarity() DESC LIMIT 5""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND category = 'tutorial' ORDER BY similarity() DESC LIMIT 5""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND category = 'tutorial' ORDER BY similarity() DESC LIMIT 5""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
# IN: filter by a set of values
results = db.execute_query( "SELECT id, title FROM articles WHERE category IN ('tutorial', 'research') LIMIT 10"
) # BETWEEN: range filtering
results = db.execute_query( "SELECT id, title FROM articles WHERE price BETWEEN 10 AND 100 LIMIT 10"
) # ILIKE: case-insensitive pattern matching
results = db.execute_query( "SELECT id, title FROM articles WHERE title ILIKE '%ai%' LIMIT 10"
) # IS NULL / IS NOT NULL
results = db.execute_query( "SELECT id, title FROM articles WHERE category IS NOT NULL LIMIT 10"
) # NOT + compound conditions
results = db.execute_query( "SELECT id, title FROM articles WHERE NOT (category = 'draft') AND price > 50 LIMIT 10"
)
# IN: filter by a set of values
results = db.execute_query( "SELECT id, title FROM articles WHERE category IN ('tutorial', 'research') LIMIT 10"
) # BETWEEN: range filtering
results = db.execute_query( "SELECT id, title FROM articles WHERE price BETWEEN 10 AND 100 LIMIT 10"
) # ILIKE: case-insensitive pattern matching
results = db.execute_query( "SELECT id, title FROM articles WHERE title ILIKE '%ai%' LIMIT 10"
) # IS NULL / IS NOT NULL
results = db.execute_query( "SELECT id, title FROM articles WHERE category IS NOT NULL LIMIT 10"
) # NOT + compound conditions
results = db.execute_query( "SELECT id, title FROM articles WHERE NOT (category = 'draft') AND price > 50 LIMIT 10"
)
# IN: filter by a set of values
results = db.execute_query( "SELECT id, title FROM articles WHERE category IN ('tutorial', 'research') LIMIT 10"
) # BETWEEN: range filtering
results = db.execute_query( "SELECT id, title FROM articles WHERE price BETWEEN 10 AND 100 LIMIT 10"
) # ILIKE: case-insensitive pattern matching
results = db.execute_query( "SELECT id, title FROM articles WHERE title ILIKE '%ai%' LIMIT 10"
) # IS NULL / IS NOT NULL
results = db.execute_query( "SELECT id, title FROM articles WHERE category IS NOT NULL LIMIT 10"
) # NOT + compound conditions
results = db.execute_query( "SELECT id, title FROM articles WHERE NOT (category = 'draft') AND price > 50 LIMIT 10"
)
results = db.execute_query( "SELECT id, title FROM articles WHERE title MATCH 'graph' LIMIT 5"
) for r in results: print(f" {r['payload']['title']}")
results = db.execute_query( "SELECT id, title FROM articles WHERE title MATCH 'graph' LIMIT 5"
) for r in results: print(f" {r['payload']['title']}")
results = db.execute_query( "SELECT id, title FROM articles WHERE title MATCH 'graph' LIMIT 5"
) for r in results: print(f" {r['payload']['title']}")
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND title MATCH 'AI' ORDER BY similarity() DESC LIMIT 5""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND title MATCH 'AI' ORDER BY similarity() DESC LIMIT 5""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND title MATCH 'AI' ORDER BY similarity() DESC LIMIT 5""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND title MATCH 'AI' LIMIT 5 USING FUSION(strategy = 'rrf', k = 60)""", {"q": query_vector}
)
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND title MATCH 'AI' LIMIT 5 USING FUSION(strategy = 'rrf', k = 60)""", {"q": query_vector}
)
results = db.execute_query( """SELECT id, title, similarity() AS score FROM articles WHERE vector NEAR $q AND title MATCH 'AI' LIMIT 5 USING FUSION(strategy = 'rrf', k = 60)""", {"q": query_vector}
)
results = db.execute_query( """LET relevance = similarity() SELECT id, title, relevance AS score FROM articles WHERE vector NEAR $q ORDER BY relevance DESC LIMIT 3""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """LET relevance = similarity() SELECT id, title, relevance AS score FROM articles WHERE vector NEAR $q ORDER BY relevance DESC LIMIT 3""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """LET relevance = similarity() SELECT id, title, relevance AS score FROM articles WHERE vector NEAR $q ORDER BY relevance DESC LIMIT 3""", {"q": query_vector}
) for r in results: print(f" [{r['score']:.3f}] {r['payload']['title']}")
results = db.execute_query( """LET hybrid = 0.7 * vector_score + 0.3 * bm25_score SELECT id, title, hybrid AS score FROM articles WHERE vector NEAR $q AND title MATCH 'search' ORDER BY hybrid DESC LIMIT 5""", {"q": query_vector}
)
results = db.execute_query( """LET hybrid = 0.7 * vector_score + 0.3 * bm25_score SELECT id, title, hybrid AS score FROM articles WHERE vector NEAR $q AND title MATCH 'search' ORDER BY hybrid DESC LIMIT 5""", {"q": query_vector}
)
results = db.execute_query( """LET hybrid = 0.7 * vector_score + 0.3 * bm25_score SELECT id, title, hybrid AS score FROM articles WHERE vector NEAR $q AND title MATCH 'search' ORDER BY hybrid DESC LIMIT 5""", {"q": query_vector}
)
LET base = 0.6 * vector_score + 0.4 * bm25_score
LET boosted = base * 1.5
SELECT *, boosted AS final_score
FROM docs
WHERE vector NEAR $v AND content MATCH 'AI'
ORDER BY boosted DESC
LIMIT 10
LET base = 0.6 * vector_score + 0.4 * bm25_score
LET boosted = base * 1.5
SELECT *, boosted AS final_score
FROM docs
WHERE vector NEAR $v AND content MATCH 'AI'
ORDER BY boosted DESC
LIMIT 10
LET base = 0.6 * vector_score + 0.4 * bm25_score
LET boosted = base * 1.5
SELECT *, boosted AS final_score
FROM docs
WHERE vector NEAR $v AND content MATCH 'AI'
ORDER BY boosted DESC
LIMIT 10
import json # Insert nodes with _labels (required for MATCH pattern matching)
db.execute_query( "INSERT NODE INTO knowledge (id = 1, payload = '%s')" % json.dumps({"name": "Alice", "role": "engineer", "_labels": ["Person"]})
)
db.execute_query( "INSERT NODE INTO knowledge (id = 2, payload = '%s')" % json.dumps({"name": "Bob", "role": "researcher", "_labels": ["Person"]})
)
db.execute_query( "INSERT NODE INTO knowledge (id = 3, payload = '%s')" % json.dumps({"name": "Acme Corp", "industry": "tech", "_labels": ["Company"]})
) # Add vectors to nodes (needed for combined vector + graph queries)
coll = db.get_collection("knowledge")
coll.upsert(1, vector=make_vector(), payload={"name": "Alice", "role": "engineer", "_labels": ["Person"]})
coll.upsert(2, vector=make_vector(), payload={"name": "Bob", "role": "researcher", "_labels": ["Person"]})
coll.upsert(3, vector=make_vector(), payload={"name": "Acme Corp", "industry": "tech", "_labels": ["Company"]}) # Insert edges
db.execute_query("INSERT EDGE INTO knowledge (source = 1, target = 2, label = 'KNOWS')")
db.execute_query("INSERT EDGE INTO knowledge (source = 1, target = 3, label = 'WORKS_AT')")
db.execute_query("INSERT EDGE INTO knowledge (source = 2, target = 3, label = 'WORKS_AT')")
import json # Insert nodes with _labels (required for MATCH pattern matching)
db.execute_query( "INSERT NODE INTO knowledge (id = 1, payload = '%s')" % json.dumps({"name": "Alice", "role": "engineer", "_labels": ["Person"]})
)
db.execute_query( "INSERT NODE INTO knowledge (id = 2, payload = '%s')" % json.dumps({"name": "Bob", "role": "researcher", "_labels": ["Person"]})
)
db.execute_query( "INSERT NODE INTO knowledge (id = 3, payload = '%s')" % json.dumps({"name": "Acme Corp", "industry": "tech", "_labels": ["Company"]})
) # Add vectors to nodes (needed for combined vector + graph queries)
coll = db.get_collection("knowledge")
coll.upsert(1, vector=make_vector(), payload={"name": "Alice", "role": "engineer", "_labels": ["Person"]})
coll.upsert(2, vector=make_vector(), payload={"name": "Bob", "role": "researcher", "_labels": ["Person"]})
coll.upsert(3, vector=make_vector(), payload={"name": "Acme Corp", "industry": "tech", "_labels": ["Company"]}) # Insert edges
db.execute_query("INSERT EDGE INTO knowledge (source = 1, target = 2, label = 'KNOWS')")
db.execute_query("INSERT EDGE INTO knowledge (source = 1, target = 3, label = 'WORKS_AT')")
db.execute_query("INSERT EDGE INTO knowledge (source = 2, target = 3, label = 'WORKS_AT')")
import json # Insert nodes with _labels (required for MATCH pattern matching)
db.execute_query( "INSERT NODE INTO knowledge (id = 1, payload = '%s')" % json.dumps({"name": "Alice", "role": "engineer", "_labels": ["Person"]})
)
db.execute_query( "INSERT NODE INTO knowledge (id = 2, payload = '%s')" % json.dumps({"name": "Bob", "role": "researcher", "_labels": ["Person"]})
)
db.execute_query( "INSERT NODE INTO knowledge (id = 3, payload = '%s')" % json.dumps({"name": "Acme Corp", "industry": "tech", "_labels": ["Company"]})
) # Add vectors to nodes (needed for combined vector + graph queries)
coll = db.get_collection("knowledge")
coll.upsert(1, vector=make_vector(), payload={"name": "Alice", "role": "engineer", "_labels": ["Person"]})
coll.upsert(2, vector=make_vector(), payload={"name": "Bob", "role": "researcher", "_labels": ["Person"]})
coll.upsert(3, vector=make_vector(), payload={"name": "Acme Corp", "industry": "tech", "_labels": ["Company"]}) # Insert edges
db.execute_query("INSERT EDGE INTO knowledge (source = 1, target = 2, label = 'KNOWS')")
db.execute_query("INSERT EDGE INTO knowledge (source = 1, target = 3, label = 'WORKS_AT')")
db.execute_query("INSERT EDGE INTO knowledge (source = 2, target = 3, label = 'WORKS_AT')")
# Find people who know other people
results = db.execute_query( "SELECT * FROM knowledge WHERE MATCH (a:Person)-[:KNOWS]->(b) LIMIT 10"
)
for r in results: print(f" {r['payload']['name']} ({r['payload']['role']})")
# Find people who know other people
results = db.execute_query( "SELECT * FROM knowledge WHERE MATCH (a:Person)-[:KNOWS]->(b) LIMIT 10"
)
for r in results: print(f" {r['payload']['name']} ({r['payload']['role']})")
# Find people who know other people
results = db.execute_query( "SELECT * FROM knowledge WHERE MATCH (a:Person)-[:KNOWS]->(b) LIMIT 10"
)
for r in results: print(f" {r['payload']['name']} ({r['payload']['role']})")
Alice (engineer)
Alice (engineer)
Alice (engineer)
# Find everyone who works at a company
results = db.execute_query( "SELECT * FROM knowledge WHERE MATCH (p:Person)-[:WORKS_AT]->(c:Company) LIMIT 10"
)
for r in results: print(f" {r['payload']['name']}")
# Find everyone who works at a company
results = db.execute_query( "SELECT * FROM knowledge WHERE MATCH (p:Person)-[:WORKS_AT]->(c:Company) LIMIT 10"
)
for r in results: print(f" {r['payload']['name']}")
# Find everyone who works at a company
results = db.execute_query( "SELECT * FROM knowledge WHERE MATCH (p:Person)-[:WORKS_AT]->(c:Company) LIMIT 10"
)
for r in results: print(f" {r['payload']['name']}")
Bob Alice
Bob Alice
Bob Alice
# Find people who work at a company AND are similar to a query vector
results = db.execute_query( """SELECT * FROM knowledge WHERE vector NEAR $v AND MATCH (p:Person)-[:WORKS_AT]->(c:Company) LIMIT 5""", {"q": query_vector}
) # Graph pattern + scalar filter
results = db.execute_query( """SELECT * FROM knowledge WHERE MATCH (a:Person)-[:WORKS_AT]->(b) AND role = 'engineer' LIMIT 10"""
)
for r in results: print(f" {r['payload']['name']} - {r['payload']['role']}")
# Find people who work at a company AND are similar to a query vector
results = db.execute_query( """SELECT * FROM knowledge WHERE vector NEAR $v AND MATCH (p:Person)-[:WORKS_AT]->(c:Company) LIMIT 5""", {"q": query_vector}
) # Graph pattern + scalar filter
results = db.execute_query( """SELECT * FROM knowledge WHERE MATCH (a:Person)-[:WORKS_AT]->(b) AND role = 'engineer' LIMIT 10"""
)
for r in results: print(f" {r['payload']['name']} - {r['payload']['role']}")
# Find people who work at a company AND are similar to a query vector
results = db.execute_query( """SELECT * FROM knowledge WHERE vector NEAR $v AND MATCH (p:Person)-[:WORKS_AT]->(c:Company) LIMIT 5""", {"q": query_vector}
) # Graph pattern + scalar filter
results = db.execute_query( """SELECT * FROM knowledge WHERE MATCH (a:Person)-[:WORKS_AT]->(b) AND role = 'engineer' LIMIT 10"""
)
for r in results: print(f" {r['payload']['name']} - {r['payload']['role']}")
edges = db.execute_query("SELECT EDGES FROM knowledge WHERE source = 1")
for e in edges: print(f" {e['payload']['label']}: {e['payload']['source']} -> {e['payload']['target']}")
edges = db.execute_query("SELECT EDGES FROM knowledge WHERE source = 1")
for e in edges: print(f" {e['payload']['label']}: {e['payload']['source']} -> {e['payload']['target']}")
edges = db.execute_query("SELECT EDGES FROM knowledge WHERE source = 1")
for e in edges: print(f" {e['payload']['label']}: {e['payload']['source']} -> {e['payload']['target']}")
KNOWS: 1 -> 2 WORKS_AT: 1 -> 3
KNOWS: 1 -> 2 WORKS_AT: 1 -> 3
KNOWS: 1 -> 2 WORKS_AT: 1 -> 3
db.execute_query( """INSERT EDGE INTO knowledge (source = 1, target = 2, label = 'COLLABORATES') WITH PROPERTIES (project = 'VelesDB', since = 2024)"""
)
db.execute_query( """INSERT EDGE INTO knowledge (source = 1, target = 2, label = 'COLLABORATES') WITH PROPERTIES (project = 'VelesDB', since = 2024)"""
)
db.execute_query( """INSERT EDGE INTO knowledge (source = 1, target = 2, label = 'COLLABORATES') WITH PROPERTIES (project = 'VelesDB', since = 2024)"""
)
# Fast search (autocomplete, suggestions)
results = db.execute_query( "SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (mode = 'fast')", {"q": query_vector}
) # Accurate search (production queries)
results = db.execute_query( "SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (mode = 'accurate')", {"q": query_vector}
) # Custom HNSW parameters
results = db.execute_query( """SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (ef_search = 256, rerank = true)""", {"q": query_vector}
)
# Fast search (autocomplete, suggestions)
results = db.execute_query( "SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (mode = 'fast')", {"q": query_vector}
) # Accurate search (production queries)
results = db.execute_query( "SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (mode = 'accurate')", {"q": query_vector}
) # Custom HNSW parameters
results = db.execute_query( """SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (ef_search = 256, rerank = true)""", {"q": query_vector}
)
# Fast search (autocomplete, suggestions)
results = db.execute_query( "SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (mode = 'fast')", {"q": query_vector}
) # Accurate search (production queries)
results = db.execute_query( "SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (mode = 'accurate')", {"q": query_vector}
) # Custom HNSW parameters
results = db.execute_query( """SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 5 WITH (ef_search = 256, rerank = true)""", {"q": query_vector}
)
# Update a field
db.execute_query("UPDATE articles SET category = 'advanced' WHERE id = 2") # Delete a row (WHERE is mandatory for safety)
db.execute_query("DELETE FROM articles WHERE id = 7") # Upsert (insert or update)
db.execute_query( "UPSERT INTO articles (id, vector, title, category) VALUES ($id, $v, 'Updated article', 'guide')", {"id": 2, "v": make_vector()}
)
# Update a field
db.execute_query("UPDATE articles SET category = 'advanced' WHERE id = 2") # Delete a row (WHERE is mandatory for safety)
db.execute_query("DELETE FROM articles WHERE id = 7") # Upsert (insert or update)
db.execute_query( "UPSERT INTO articles (id, vector, title, category) VALUES ($id, $v, 'Updated article', 'guide')", {"id": 2, "v": make_vector()}
)
# Update a field
db.execute_query("UPDATE articles SET category = 'advanced' WHERE id = 2") # Delete a row (WHERE is mandatory for safety)
db.execute_query("DELETE FROM articles WHERE id = 7") # Upsert (insert or update)
db.execute_query( "UPSERT INTO articles (id, vector, title, category) VALUES ($id, $v, 'Updated article', 'guide')", {"id": 2, "v": make_vector()}
)
# UNION: combine tech and finance products, remove duplicates
results = db.execute_query(""" SELECT id, title FROM articles WHERE category = 'tutorial' UNION SELECT id, title FROM articles WHERE category = 'guide'
""") # INTERSECT: find items in both result sets
results = db.execute_query(""" SELECT id, title FROM articles WHERE category = 'tutorial' INTERSECT SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 10
""", {"q": query_vector}) # EXCEPT: items in first set but not in second
results = db.execute_query(""" SELECT id FROM articles WHERE category = 'tutorial' EXCEPT SELECT id FROM articles WHERE title MATCH 'graph'
""")
# UNION: combine tech and finance products, remove duplicates
results = db.execute_query(""" SELECT id, title FROM articles WHERE category = 'tutorial' UNION SELECT id, title FROM articles WHERE category = 'guide'
""") # INTERSECT: find items in both result sets
results = db.execute_query(""" SELECT id, title FROM articles WHERE category = 'tutorial' INTERSECT SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 10
""", {"q": query_vector}) # EXCEPT: items in first set but not in second
results = db.execute_query(""" SELECT id FROM articles WHERE category = 'tutorial' EXCEPT SELECT id FROM articles WHERE title MATCH 'graph'
""")
# UNION: combine tech and finance products, remove duplicates
results = db.execute_query(""" SELECT id, title FROM articles WHERE category = 'tutorial' UNION SELECT id, title FROM articles WHERE category = 'guide'
""") # INTERSECT: find items in both result sets
results = db.execute_query(""" SELECT id, title FROM articles WHERE category = 'tutorial' INTERSECT SELECT id, title FROM articles WHERE vector NEAR $q LIMIT 10
""", {"q": query_vector}) # EXCEPT: items in first set but not in second
results = db.execute_query(""" SELECT id FROM articles WHERE category = 'tutorial' EXCEPT SELECT id FROM articles WHERE title MATCH 'graph'
""")
# Unique categories
results = db.execute_query("SELECT DISTINCT category FROM articles") # DISTINCT with vector search (dedup by payload value after search)
results = db.execute_query( "SELECT DISTINCT category FROM articles WHERE vector NEAR $q LIMIT 20", {"q": query_vector}
)
# Unique categories
results = db.execute_query("SELECT DISTINCT category FROM articles") # DISTINCT with vector search (dedup by payload value after search)
results = db.execute_query( "SELECT DISTINCT category FROM articles WHERE vector NEAR $q LIMIT 20", {"q": query_vector}
)
# Unique categories
results = db.execute_query("SELECT DISTINCT category FROM articles") # DISTINCT with vector search (dedup by payload value after search)
results = db.execute_query( "SELECT DISTINCT category FROM articles WHERE vector NEAR $q LIMIT 20", {"q": query_vector}
)
import time # Insert an event with a timestamp
now = int(time.time())
db.execute_query( "INSERT INTO articles (id, vector, title, created_at) VALUES ($id, $v, 'Fresh article', $ts)", {"id": 100, "v": make_vector(), "ts": now}
) # Query using NOW() and INTERVAL
results = db.execute_query( "SELECT id, title FROM articles WHERE created_at > NOW() - INTERVAL '24 hours' LIMIT 10"
)
import time # Insert an event with a timestamp
now = int(time.time())
db.execute_query( "INSERT INTO articles (id, vector, title, created_at) VALUES ($id, $v, 'Fresh article', $ts)", {"id": 100, "v": make_vector(), "ts": now}
) # Query using NOW() and INTERVAL
results = db.execute_query( "SELECT id, title FROM articles WHERE created_at > NOW() - INTERVAL '24 hours' LIMIT 10"
)
import time # Insert an event with a timestamp
now = int(time.time())
db.execute_query( "INSERT INTO articles (id, vector, title, created_at) VALUES ($id, $v, 'Fresh article', $ts)", {"id": 100, "v": make_vector(), "ts": now}
) # Query using NOW() and INTERVAL
results = db.execute_query( "SELECT id, title FROM articles WHERE created_at > NOW() - INTERVAL '24 hours' LIMIT 10"
)
plan = db.execute_query( "EXPLAIN SELECT * FROM articles WHERE vector NEAR $q LIMIT 5", {"q": query_vector}
) print(plan[0]['payload']['tree'])
plan = db.execute_query( "EXPLAIN SELECT * FROM articles WHERE vector NEAR $q LIMIT 5", {"q": query_vector}
) print(plan[0]['payload']['tree'])
plan = db.execute_query( "EXPLAIN SELECT * FROM articles WHERE vector NEAR $q LIMIT 5", {"q": query_vector}
) print(plan[0]['payload']['tree'])
Query Plan:
├─ VectorSearch
│ ├─ Collection: articles
│ ├─ ef_search: 100
│ └─ Candidates: 5
└─ Limit: 5 Estimated cost: 0.101ms
Index used: HNSW
Query Plan:
├─ VectorSearch
│ ├─ Collection: articles
│ ├─ ef_search: 100
│ └─ Candidates: 5
└─ Limit: 5 Estimated cost: 0.101ms
Index used: HNSW
Query Plan:
├─ VectorSearch
│ ├─ Collection: articles
│ ├─ ef_search: 100
│ └─ Candidates: 5
└─ Limit: 5 Estimated cost: 0.101ms
Index used: HNSW
# Create an index on category
db.execute_query("CREATE INDEX ON articles (category)") # Analyze collection statistics for the query optimizer
db.execute_query("ANALYZE articles")
# Create an index on category
db.execute_query("CREATE INDEX ON articles (category)") # Analyze collection statistics for the query optimizer
db.execute_query("ANALYZE articles")
# Create an index on category
db.execute_query("CREATE INDEX ON articles (category)") # Analyze collection statistics for the query optimizer
db.execute_query("ANALYZE articles")
memory = db.agent_memory(384) # Store some facts via the SDK
memory.semantic.store(1, "User prefers Python", make_vector())
memory.semantic.store(2, "User works in healthcare", make_vector()) # Query them with VelesQL
results = db.execute_query( """SELECT * FROM _semantic_memory WHERE vector NEAR $q LIMIT 5 WITH (mode = 'accurate')""", {"q": make_vector()}
) for r in results: print(f" {r['payload']['content']}")
memory = db.agent_memory(384) # Store some facts via the SDK
memory.semantic.store(1, "User prefers Python", make_vector())
memory.semantic.store(2, "User works in healthcare", make_vector()) # Query them with VelesQL
results = db.execute_query( """SELECT * FROM _semantic_memory WHERE vector NEAR $q LIMIT 5 WITH (mode = 'accurate')""", {"q": make_vector()}
) for r in results: print(f" {r['payload']['content']}")
memory = db.agent_memory(384) # Store some facts via the SDK
memory.semantic.store(1, "User prefers Python", make_vector())
memory.semantic.store(2, "User works in healthcare", make_vector()) # Query them with VelesQL
results = db.execute_query( """SELECT * FROM _semantic_memory WHERE vector NEAR $q LIMIT 5 WITH (mode = 'accurate')""", {"q": make_vector()}
) for r in results: print(f" {r['payload']['content']}") - VelesDB on GitHub (~3MB binary, source-available under Elastic License 2.0)
- Documentation and examples
- VelesQL Specification