Skip to main content
Use an OpenAI model to generate embeddings for your vectorizer.

Purpose

  • Define which OpenAI embedding model to use
  • Specify the dimensionality of the embeddings
  • Configure optional parameters like user identifier for API calls
  • Set the name of the environment variable that holds your OpenAI API key

Samples

Basic OpenAI embedding

SELECT ai.create_vectorizer(
    'blog_posts'::regclass,
    loading => ai.loading_column('content'),
    embedding => ai.embedding_openai('text-embedding-3-small', 768),
    chunking => ai.chunking_character_text_splitter(512)
);

With custom API key name

SELECT ai.create_vectorizer(
    'documents'::regclass,
    loading => ai.loading_column('content'),
    embedding => ai.embedding_openai(
        'text-embedding-3-small',
        768,
        api_key_name => 'MY_OPENAI_API_KEY'
    ),
    chunking => ai.chunking_character_text_splitter(512)
);

With user tracking

SELECT ai.create_vectorizer(
    'user_content'::regclass,
    loading => ai.loading_column('text'),
    embedding => ai.embedding_openai(
        'text-embedding-3-small',
        768,
        chat_user => 'analytics_team'
    ),
    chunking => ai.chunking_character_text_splitter(512)
);

With custom base URL

SELECT ai.create_vectorizer(
    'data_table'::regclass,
    loading => ai.loading_column('content'),
    embedding => ai.embedding_openai(
        'text-embedding-3-small',
        768,
        base_url => 'https://custom-openai-endpoint.com/v1'
    ),
    chunking => ai.chunking_character_text_splitter(512)
);

Arguments

NameTypeDefaultRequiredDescription
modeltext-Name of the OpenAI embedding model (e.g., text-embedding-3-small)
dimensionsint-Number of dimensions for the embedding vectors
chat_usertext-Identifier for the user making the API call (for tracking/monitoring)
api_key_nametextOPENAI_API_KEYName of the environment variable containing the OpenAI API key
base_urltext-Custom base URL for the OpenAI API

Returns

A JSON configuration object for use in create_vectorizer().