LLM extension
The llm extension helps you run LLM-based workflows directly within Ladybug using Cypher.
Currently, this extension provides the following function:
CREATE_EMBEDDING: Create embeddings from text
Usage
Please see Install an extension and Load an extension first before getting started.
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
- Type:
PROVIDER: The embedding provider.- Type:
STRING
- Type:
MODEL: The identifier of the embedding model.- Type:
STRING
- Type:
Additional provider-specific arguments:
DIMENSIONS: The size of the embedding vector.- Type:
INT64 - Note: This value must be positive.
- Type:
REGION: The region to send requests to.- Type:
STRING - Note: This value is required when the provider supports it.
- Type:
ENDPOINT: The endpoint to send requests to.- Type:
STRING - Default:
http://localhost:11434
- Type:
The additional arguments that you can use depends on the provider. The following table shows the arguments associated with each provider:
| Provider | dimensions | region | endpoint |
|---|---|---|---|
amazon-bedrock | - | Required | - |
google-vertex | Optional | Required | - |
google-gemini | - | - | - |
openai | Optional | - | - |
voyageai | Optional | - | - |
ollama | - | - | Optional |
Configuration
To allow API calls to the providers, you must set the appropriate environment variables:
| Provider | Required Environment Variables |
|---|---|
amazon-bedrock | AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY |
google-vertex | GOOGLE_CLOUD_PROJECT_ID, GOOGLE_VERTEX_ACCESS_KEY |
google-gemini | GOOGLE_GEMINI_API_KEY |
openai | OPENAI_API_KEY |
voyageai | VOYAGE_API_KEY |
ollama | OLLAMA_URL |
Examples
// Required REGIONRETURN 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 REGIONRETURN 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 ENDPOINTRETURN CREATE_EMBEDDING("Hello world", "ollama", "nomic-embed-text", "http://endpoint.example.com:8000");
RETURN CREATE_EMBEDDING( "Hello world", "openai", "text-embedding-3-small");// Optional DIMENSIONSRETURN CREATE_EMBEDDING( "Hello world", "openai", "text-embedding-3-small", 512);
RETURN CREATE_EMBEDDING( "Hello world", "voyageai", "voyage-3-large");// Optional DIMENSIONSRETURN CREATE_EMBEDDING( "Hello world", "voyageai", "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 Ladybug. Refer to the vector search docs for an example.