Embed Text using Embed Â
Automatically embed text into vectors using your configured embedding model.
AddV < Type >( Embed ( text ))
AddV < Type >( Embed ( text ), { properties })
SearchV < Type >( Embed ( text ), limit )
The text is automatically embedded with an embedding model of your choice (can be defined in your config.hx.json file). The default embedding model is text-embedding-ada-002 from OpenAI.
Make sure to set your OPENAI_API_KEY environment variable with your API key in the same location as the queries.hx, schema.hx and config.hx.json files. 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 from text
Query
Schema
Environment Variables (.env)
QUERY InsertTextAsVector ( content : String , created_at : Date ) =>
document <- AddV < Document >( Embed ( content ), { content : content , created_at : created_at })
RETURN document
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from datetime import datetime, timezone
from helix.client import Client
client = Client( local = True , port = 6969 )
print (client.query( "InsertTextAsVector" , {
"content" : "Machine learning is transforming the way we work." ,
"created_at" : datetime.now(timezone.utc).isoformat(),
}))
Example 2: Searching with text embeddings
Query
Schema
Environment Variables (.env)
QUERY SearchWithText ( query : String , limit : I64 ) =>
documents <- SearchV < Document >( Embed ( query ), limit )
RETURN documents
QUERY InsertTextAsVector ( content : String , created_at : Date ) =>
document <- AddV < Document >( Embed ( content ), { content : content , created_at : created_at })
RETURN document
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from datetime import datetime, timezone
from helix.client import Client
client = Client( local = True , port = 6969 )
sample_texts = [
"Artificial intelligence is revolutionizing automation" ,
"Machine learning algorithms for predictive analytics" ,
"Deep learning applications in computer vision"
]
for text in sample_texts:
client.query( "InsertTextAsVector" , {
"content" : text,
"created_at" : datetime.now(timezone.utc).isoformat(),
})
result = client.query( "SearchWithText" , {
"query" : "artificial intelligence and automation" ,
"limit" : 5 ,
})
print (result)
See all 23 lines
Example 3: Creating a vector and connecting it to a user
Query
Schema
Environment Variables (.env)
QUERY CreateUserDocument ( user_id : ID , content : String , created_at : Date ) =>
document <- AddV < Document >( Embed ( content ), { content : content , created_at : created_at })
edge <- AddE < User_to_Document_Embedding > :: From ( user_id ) :: To ( document )
RETURN document
QUERY CreateUser ( name : String , email : String ) =>
user <- AddN < User >({
name : name ,
email : email
})
RETURN user
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from datetime import datetime, timezone
from helix.client import Client
client = Client( local = True , port = 6969 )
user = client.query( "CreateUser" , {
"name" : "Alice Johnson" ,
"email" : "alice@example.com" ,
})
user_id = user[ 0 ][ "user" ][ "id" ]
result = client.query( "CreateUserDocument" , {
"user_id" : user_id,
"content" : "This is my personal note about project planning." ,
"created_at" : datetime.now(timezone.utc).isoformat(),
})
print (result)
See all 18 lines
Example 4: Semantic search with postfiltering
Query
Schema
Environment Variables (.env)
QUERY SearchRecentNotes ( query : String , limit : I64 , cutoff_date : Date ) =>
documents <- SearchV < Document >( Embed ( query ), limit )
:: WHERE ( _ :: { created_at } :: GTE ( cutoff_date ))
RETURN documents
QUERY InsertTextAsVector ( content : String , created_at : Date ) =>
document <- AddV < Document >( Embed ( content ), { content : content , created_at : created_at })
RETURN document
Here’s how to run the query using the SDKs or curl
Python
Rust
Go
TypeScript
Curl
from datetime import datetime, timezone, timedelta
from helix.client import Client
client = Client( local = True , port = 6969 )
recent_date = datetime.now(timezone.utc).isoformat()
old_date = (datetime.now(timezone.utc) - timedelta( days = 10 )).isoformat()
client.query( "InsertTextAsVector" , {
"content" : "Project milestone review scheduled for next week" ,
"created_at" : recent_date,
})
client.query( "InsertTextAsVector" , {
"content" : "Weekly status report from last month" ,
"created_at" : old_date,
})
cutoff_date = (datetime.now(timezone.utc) - timedelta( days = 7 )).isoformat()
result = client.query( "SearchRecentNotes" , {
"query" : "project deadlines and milestones" ,
"limit" : 10 ,
"cutoff_date" : cutoff_date,
})
print (result)
See all 27 lines