Create Vectors using AddV Â
Create new vector embeddings in your graph.
AddV<Type>
AddV<Type>(vector, {properties})
Currently, Helix only supports using an array of
F64 values to represent the vector.
We will be adding support for different types such as F32, binary vectors and
more in the very near future. Please reach out to us if you need a different vector type.When using the SDKs or curling the endpoint, the query name must match what is defined in the
queries.hx file exactly.Example 1: Creating a vector with no properties
QUERY InsertVector (vector: [F64]) =>
vector_node <- AddV<Document>(vector)
RETURN vector_node
// You don't need to define the properties in the schema,
// it uses [F64] by default
V::Document {}
from helix.client import Client
client = Client(local=True, port=6969)
print(client.query("InsertVector", {
"vector": [0.1, 0.2, 0.3, 0.4],
}))
use helix_rs::{HelixDB, HelixDBClient};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HelixDB::new(Some("http://localhost"), Some(6969), None);
let payload = json!({
"vector": [0.1, 0.2, 0.3, 0.4],
});
let result: serde_json::Value = client.query("InsertVector", &payload).await?;
println!("Created vector node: {result:#?}");
Ok(())
}
package main
import (
"fmt"
"log"
"github.com/HelixDB/helix-go"
)
func main() {
client := helix.NewClient("http://localhost:6969")
payload := map[string]any{
"vector": []float64{0.1, 0.2, 0.3, 0.4},
}
var result map[string]any
if err := client.Query("InsertVector", helix.WithData(payload)).Scan(&result); err != nil {
log.Fatalf("InsertVector failed: %s", err)
}
fmt.Printf("Created vector node: %#v\n", result)
}
import HelixDB from "helix-ts";
async function main() {
const client = new HelixDB("http://localhost:6969");
const result = await client.query("InsertVector", {
vector: [0.1, 0.2, 0.3, 0.4],
});
console.log("Created vector node:", result);
}
main().catch((err) => {
console.error("InsertVector query failed:", err);
});
curl -X POST \
http://localhost:6969/InsertVector \
-H 'Content-Type: application/json' \
-d '{"vector":[0.1,0.2,0.3,0.4]}'
Example 2: Creating a vector with properties
QUERY InsertVector (vector: [F64], content: String, created_at: Date) =>
vector_node <- AddV<Document>(vector, { content: content, created_at: created_at })
RETURN vector_node
V::Document {
content: String,
created_at: Date
}
from datetime import datetime, timezone
from helix.client import Client
client = Client(local=True, port=6969)
payload = {
"vector": [0.12, 0.34, 0.56, 0.78],
"content": "Quick brown fox",
"created_at": datetime.now(timezone.utc).isoformat(),
}
print(client.query("InsertVector", payload))
use chrono::Utc;
use helix_rs::{HelixDB, HelixDBClient};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HelixDB::new(Some("http://localhost"), Some(6969), None);
let payload = json!({
"vector": [0.12, 0.34, 0.56, 0.78],
"content": "Quick brown fox",
"created_at": Utc::now().to_rfc3339(),
});
let result: serde_json::Value = client.query("InsertVector", &payload).await?;
println!("Created vector node: {result:#?}");
Ok(())
}
package main
import (
"fmt"
"log"
"github.com/HelixDB/helix-go"
"time"
)
func main() {
client := helix.NewClient("http://localhost:6969")
payload := map[string]any{
"vector": []float64{0.12, 0.34, 0.56, 0.78},
"content": "Quick brown fox",
"created_at": time.Now().UTC().Format(time.RFC3339),
}
var result map[string]any
if err := client.Query("InsertVector", helix.WithData(payload)).Scan(&result); err != nil {
log.Fatalf("InsertVector failed: %s", err)
}
fmt.Printf("Created vector node: %#v\n", result)
}
import HelixDB from "helix-ts";
async function main() {
const client = new HelixDB("http://localhost:6969");
const result = await client.query("InsertVector", {
vector: [0.12, 0.34, 0.56, 0.78],
content: "Quick brown fox",
created_at: new Date().toISOString(),
});
console.log("Created vector node:", result);
}
main().catch((err) => {
console.error("InsertVector query failed:", err);
});
curl -X POST \
http://localhost:6969/InsertVector \
-H 'Content-Type: application/json' \
-d '{"vector":[0.12,0.34,0.56,0.78],"content":"Quick brown fox","created_at":"'"$(date -u +"%Y-%m-%dT%H:%M:%SZ")"'"}'
Example 3: Creating a vector and connecting it to a node
QUERY InsertVector (user_id: ID, vector: [F64], content: String, created_at: Date) =>
vector_node <- AddV<Document>(vector, { content: content, created_at: created_at })
edge <- AddE<User_to_Document_Embedding>::From(user_id)::To(vector_node)
RETURN "Success"
QUERY CreateUser (name: String, age: U8, email: String) =>
user <- AddN<User>({
name: name,
age: age,
email: email
})
RETURN user
N::User {
name: String,
age: U8,
email: String,
}
V::Document {
content: String,
created_at: Date
}
E::User_to_Document_Embedding {
From: User,
To: Document,
}
from datetime import datetime, timezone
from helix.client import Client
client = Client(local=True, port=6969)
user = client.query("CreateUser", {
"name": "Alice",
"age": 25,
"email": "alice@example.com",
})
user_id = user[0]["user"]["id"]
payload = {
"user_id": user_id,
"vector": [0.05, 0.25, 0.5, 0.75],
"content": "Favorite quotes",
"created_at": datetime.now(timezone.utc).isoformat(),
}
print(client.query("InsertVector", payload))
use chrono::Utc;
use helix_rs::{HelixDB, HelixDBClient};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HelixDB::new(Some("http://localhost"), Some(6969), None);
let alice: serde_json::Value = client.query("CreateUser", &json!({
"name": "Alice",
"age": 25,
"email": "alice@example.com",
})).await?;
let user_id = alice["user"]["id"].as_str().unwrap().to_string();
let payload = json!({
"user_id": user_id,
"vector": [0.05, 0.25, 0.5, 0.75],
"content": "Favorite quotes",
"created_at": Utc::now().to_rfc3339(),
});
let result: serde_json::Value = client.query("InsertVector", &payload).await?;
println!("InsertVector result: {result:#?}");
Ok(())
}
package main
import (
"fmt"
"log"
"time"
"github.com/HelixDB/helix-go"
)
func main() {
client := helix.NewClient("http://localhost:6969")
userPayload := map[string]any{
"name": "Alice",
"age": uint8(25),
"email": "alice@example.com",
}
var user map[string]any
if err := client.Query("CreateUser", helix.WithData(userPayload)).Scan(&user); err != nil {
log.Fatalf("CreateUser failed: %s", err)
}
userID := user["user"].(map[string]any)["id"].(string)
payload := map[string]any{
"user_id": userID,
"vector": []float64{0.05, 0.25, 0.5, 0.75},
"content": "Favorite quotes",
"created_at": time.Now().UTC().Format(time.RFC3339),
}
var result map[string]any
if err := client.Query("InsertVector", helix.WithData(payload)).Scan(&result); err != nil {
log.Fatalf("InsertVector failed: %s", err)
}
fmt.Printf("InsertVector result: %#v\n", result)
}
import HelixDB from "helix-ts";
async function main() {
const client = new HelixDB("http://localhost:6969");
const user = await client.query("CreateUser", {
name: "Alice",
age: 25,
email: "alice@example.com",
});
const userId: string = user.user.id;
const result = await client.query("InsertVector", {
user_id: userId,
vector: [0.05, 0.25, 0.5, 0.75],
content: "Favorite quotes",
created_at: new Date().toISOString(),
});
console.log("InsertVector result:", result);
}
main().catch((err) => {
console.error("InsertVector query failed:", err);
});
curl -X POST \
http://localhost:6969/CreateUser \
-H 'Content-Type: application/json' \
-d '{"name":"Alice","age":25,"email":"alice@example.com"}'
curl -X POST \
http://localhost:6969/InsertVector \
-H 'Content-Type: application/json' \
-d '{"user_id":"<user_id>","vector":[0.05,0.25,0.5,0.75],"content":"Favorite quotes","created_at":"'"$(date -u +"%Y-%m-%dT%H:%M:%SZ")"'"}'
Example 4: Using the built in Embed function
You can also use the built in Embed function to embed the text without sending in the array of floats. It uses the embedding model defined in your config.hx.json file.
QUERY InsertVector (content: String, created_at: Date) =>
vector_node <- AddV<Document>(Embed(content), { content: content, created_at: created_at })
RETURN vector_node
V::Document {
content: String,
created_at: Date
}
OPENAI_API_KEY=your_api_key
from datetime import datetime, timezone
from helix.client import Client
client = Client(local=True, port=6969)
payload = {
"content": "Quick summary of a meeting",
"created_at": datetime.now(timezone.utc).isoformat(),
}
print(client.query("InsertVector", payload))
use chrono::Utc;
use helix_rs::{HelixDB, HelixDBClient};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = HelixDB::new(Some("http://localhost"), Some(6969), None);
let payload = json!({
"content": "Quick summary of a meeting",
"created_at": Utc::now().to_rfc3339(),
});
let result: serde_json::Value = client.query("InsertVector", &payload).await?;
println!("InsertVector result: {result:#?}");
Ok(())
}
package main
import (
"fmt"
"log"
"time"
"github.com/HelixDB/helix-go"
)
func main() {
client := helix.NewClient("http://localhost:6969")
payload := map[string]any{
"content": "Quick summary of a meeting",
"created_at": time.Now().UTC().Format(time.RFC3339),
}
var result map[string]any
if err := client.Query("InsertVector", helix.WithData(payload)).Scan(&result); err != nil {
log.Fatalf("InsertVector failed: %s", err)
}
fmt.Printf("InsertVector result: %#v\n", result)
}
import HelixDB from "helix-ts";
async function main() {
const client = new HelixDB("http://localhost:6969");
const result = await client.query("InsertVector", {
content: "Quick summary of a meeting",
created_at: new Date().toISOString(),
});
console.log("InsertVector result:", result);
}
main().catch((err) => {
console.error("InsertVector query failed:", err);
});
curl -X POST \
http://localhost:6969/InsertVector \
-H 'Content-Type: application/json' \
-d '{"content":"Quick summary of a meeting","created_at":"'"$(date -u +"%Y-%m-%dT%H:%M:%SZ")"'"}'