Built-in AI Functions
Databend provides built-in AI functions powered by Azure OpenAI Service for seamless integration of AI capabilities into your SQL workflows.
warning
Data Privacy Notice: When using built-in AI functions, your data is sent to Azure OpenAI Service. By using these functions, you acknowledge this data transfer and agree to the Azure OpenAI Data Privacy terms.
Function | Description | Use Cases |
---|---|---|
ai_text_completion | Generates text based on prompts | • Content generation • Question answering • Summarization |
ai_embedding_vector | Converts text to vector representations | • Semantic search • Document similarity • Content recommendation |
cosine_distance | Calculates similarity between vectors | • Finding similar documents • Ranking search results |
Vector Storage in Databend
Databend stores embedding vectors using the ARRAY(FLOAT NOT NULL)
data type, enabling direct similarity calculations with the cosine_distance
function in SQL.
Example: Semantic Search with Embeddings
-- Create a table for documents with embeddings
CREATE TABLE articles (
id INT,
title VARCHAR,
content VARCHAR,
embedding ARRAY(FLOAT NOT NULL)
);
-- Store documents with their vector embeddings
INSERT INTO articles (id, title, content, embedding)
VALUES
(1, 'Python for Data Science', 'Python is a versatile programming language...',
ai_embedding_vector('Python is a versatile programming language...')),
(2, 'Introduction to R', 'R is a popular programming language for statistics...',
ai_embedding_vector('R is a popular programming language for statistics...'));
-- Find semantically similar documents
SELECT
id, title,
cosine_distance(embedding, ai_embedding_vector('How to use Python in data analysis?')) AS similarity
FROM articles
ORDER BY similarity ASC
LIMIT 3;
Example: Text Generation
-- Generate text based on a prompt
SELECT ai_text_completion('Explain the benefits of cloud data warehouses in three points:') AS completion;
Getting Started
Try these AI capabilities on Databend Cloud with a free trial.