Skip to content
Blog

LLM extension

The llm extension helps you run LLM-based workflows directly within Kuzu using Cypher.

Currently, this extension provides the following function:

  • CREATE_EMBEDDING: Create embeddings from text

Usage

INSTALL llm;
LOAD llm;

Create embeddings

The CREATE_EMBEDDING function allows you to create embeddings from text using the following providers:

The general form of the function is shown below. It returns an embedding of type LIST[FLOAT].

CREATE_EMBEDDING(
// Required arguments
<PROMPT>,
<PROVIDER>,
<MODEL>
// Provider-specific arguments
<DIMENSIONS>,
<REGION>,
<ENDPOINT>
);

Required arguments:

  • PROMPT: The input text to embed.
    • Type: STRING
  • PROVIDER: The embedding provider.
    • Type: STRING
  • MODEL: The identifier of the embedding model.
    • Type: STRING

Additional provider-specific arguments:

  • DIMENSIONS: The size of the embedding vector.
    • Type: INT64
    • Note: This value must be positive.
  • REGION: The region to send requests to.
    • Type: STRING
    • Note: This value is required when the provider supports it.
  • ENDPOINT: The endpoint to send requests to.
    • Type: STRING
    • Default: http://localhost:11434

The additional arguments that you can use depends on the provider. The following table shows the arguments associated with each provider:

Providerdimensionsregionendpoint
amazon-bedrock-Required-
google-vertexOptionalRequired-
google-gemini---
open-aiOptional--
voyage-aiOptional--
ollama--Optional

Configuration

To allow API calls to the providers, you must set the appropriate environment variables:

ProviderRequired Environment Variables
amazon-bedrockAWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY
google-vertexGOOGLE_CLOUD_PROJECT_ID, GOOGLE_VERTEX_ACCESS_KEY
google-geminiGOOGLE_GEMINI_API_KEY
open-aiOPENAI_API_KEY
voyage-aiVOYAGE_API_KEY
ollamaOLLAMA_URL

Examples

// Required REGION
RETURN CREATE_EMBEDDING("Hello world", "amazon-bedrock", "amazon.titan-embed-text-v1", "us-east-1");
RETURN CREATE_EMBEDDING("Hello world", "google-gemini", "gemini-embedding-exp-03-07");
// Required REGION
RETURN CREATE_EMBEDDING("Hello world", "google-vertex", "gemini-embedding-001", "us-central1");
// Optional DIMENSIONS and required REGION.
RETURN CREATE_EMBEDDING("Hello world", "google-vertex", "gemini-embedding-001", 256, "us-central1");
RETURN CREATE_EMBEDDING("Hello world", "ollama", "nomic-embed-text");
// Optional ENDPOINT
RETURN CREATE_EMBEDDING("Hello world", "ollama", "nomic-embed-text", "http://endpoint.example.com:8000");
RETURN CREATE_EMBEDDING( "Hello world", "open-ai", "text-embedding-3-small");
// Optional DIMENSIONS
RETURN CREATE_EMBEDDING( "Hello world", "open-ai", "text-embedding-3-small", 512);
RETURN CREATE_EMBEDDING( "Hello world", "voyage-ai", "voyage-3-large");
// Optional DIMENSIONS
RETURN CREATE_EMBEDDING( "Hello world", "voyage-ai", "voyage-3-large", 512);

Storing embeddings in a vector index

The CREATE_EMBEDDING function can be used together with the vector extension to store and search embeddings directly in Kuzu. Refer to the vector search docs for an example.