flock

LLM- und RAG-Erweiterung zur Kombination von Analytik und semantischer Analyse

Maintainer: anasdorbani, queryproc, iZarrios

Installation und Laden

INSTALL flock FROM community;
LOAD flock;

Beispiel

-- After loading, any function call will throw an error if the provider's secret doesn't exist
-- Create your provider secret by following the [documentation](https://dais-polymtl.github.io/flock/docs/what-is-flock/). For example, you can create a default OpenAI API key as follows:
D CREATE SECRET (TYPE OPENAI, API_KEY 'your-api-key');
-- Call an OpenAI model with a predefined prompt ('Tell me hello world') and default model ('gpt-4o-mini')
D SELECT llm_complete({'model_name': 'default'}, {'prompt_name': 'hello-world'});
┌──────────────────────────────────────────┐
│ llm_complete(hello_world, default_model) │
varchar
├──────────────────────────────────────────┤
│ Hello world │
└──────────────────────────────────────────┘
-- Check the prompts and supported models
D GET PROMPTS;
D GET MODELS;
-- Create a new prompt for summarizing text
D CREATE PROMPT('summarize', 'summarize the text into 1 word: {{text}}');
-- Create a variable name for the model to do the summarizing
D CREATE MODEL('summarizer-model', 'gpt-4o', 'openai');
-- Summarize text and pass it as parameter
D SELECT llm_complete({'model_name': 'summarizer-model'}, {'prompt_name': 'summarize','context_columns': [{'data': 'We support more functions and approaches to combine relational analytics and semantic analysis. Check our repo for documentation and examples.'}}]);

Über flock

Flock ist eine experimentelle DuckDB-Erweiterung, die die nahtlose Integration großer Sprachmodelle (LLMs) und von Retrieval-Augmented Generation (RAG) direkt in SQL ermöglicht.

Sie führt MODEL- und PROMPT-Objekte als erstklassige SQL-Entitäten ein, sodass sich LLM-Interaktionen einfach definieren, verwalten und wiederverwenden lassen. Kernfunktionen wie llm_complete, llm_filter und llm_rerank ermöglichen Generierung, semantisches Filtern und Ranking — alles aus SQL.

📄 Weitere Details und Beispiele finden Sie in der Flock-Dokumentation.

Hinweis: Flock ist Teil der laufenden Forschung des Data & AI Systems (DAIS) Laboratory @ Polytechnique Montréal. Die Erweiterung wird aktiv weiterentwickelt, und einzelne Funktionen können sich ändern. Feedback und Beiträge sind willkommen!

Hinzugefügte Funktionen

function_name function_type description comment examples
llm_complete scalar Generates text completions using a specified language model Requires model config and prompt; supports text and image inputs [SELECT llm_complete({‘model_name’: ‘gpt-4o’}, {‘prompt’: ‘Explain the purpose of Flock.’});]
llm_filter scalar Filters data based on language model evaluations returning boolean values Commonly used in WHERE clause; supports text and image inputs [SELECT * FROM data WHERE llm_filter({‘model_name’: ‘gpt-4o’}, {‘prompt’: ‘Is this eco-friendly?’, ‘context_columns’: [{‘data’: content}]});]
llm_embedding scalar Generates embeddings for input text Useful for semantic similarity; text only (no image support) [SELECT llm_embedding({‘model_name’: ‘text-embedding-3-small’}, {‘context_columns’: [{‘data’: product_name}]}) FROM products;]
llm_reduce aggregate Aggregates multiple inputs into a single output using a language model Use with GROUP BY; summarizes or combines multiple rows [SELECT category, llm_reduce({‘model_name’: ‘gpt-4o’}, {‘prompt’: ‘Summarize the following’, ‘context_columns’: [{‘data’: content}]}) FROM documents GROUP BY category;]
llm_rerank aggregate Reorders query results based on relevance scores from a language model Uses sliding window for long lists; returns JSON array of reranked rows [SELECT llm_rerank({‘model_name’: ‘gpt-4o’}, {‘prompt’: ‘AI and machine learning’, ‘context_columns’: [{‘data’: document_title}, {‘data’: document_content}]}) FROM search_results;]
llm_first aggregate Selects the top-ranked result after reranking by relevance Returns single JSON object; use with or without GROUP BY [SELECT llm_first({‘model_name’: ‘gpt-4o’}, {‘prompt’: ‘high-performance computing’, ‘context_columns’: [{‘data’: product_name}, {‘data’: product_description}]}) FROM products;]
llm_last aggregate Selects the bottom-ranked result after reranking by relevance Returns single JSON object; use with or without GROUP BY [SELECT llm_last({‘model_name’: ‘gpt-4o’}, {‘prompt’: ‘premium audio quality’, ‘context_columns’: [{‘data’: product_name}, {‘data’: product_description}]}) FROM products;]
fusion_rrf scalar Implements Reciprocal Rank Fusion (RRF) to combine rankings Input: document ranks (1 = best); use DENSE_RANK() for rank-based input [SELECT fusion_rrf(bm25_rank, embedding_rank) AS combined_score FROM ranked_results;]
fusion_combsum scalar Sums normalized scores from different scoring systems Input: normalized scores (0-1); NULL/NaN/0 treated as 0 [SELECT fusion_combsum(bm25_normalized, embedding_normalized) FROM combined_scores;]
fusion_combmnz scalar Sums normalized scores multiplied by hit count Enhances impact of frequently occurring items across scoring systems [SELECT fusion_combmnz(score1, score2) FROM combined_scores;]
fusion_combmed scalar Computes the median of normalized scores Reduces effect of outliers in combined scores [SELECT fusion_combmed(score1, score2) FROM combined_scores;]
fusion_combanz scalar Calculates the average of normalized scores Provides balanced aggregation of scores; NULL/NaN/0 treated as 0 [SELECT fusion_combanz(score1, score2) FROM combined_scores;]
flock_get_metrics scalar Returns usage metrics for LLM function calls in the current session Returns JSON with api_calls tokens and timing per function [SELECT flock_get_metrics();]
flock_get_debug_metrics scalar Returns detailed debug metrics including registration order Useful for debugging multi-function queries [SELECT flock_get_debug_metrics();]
flock_reset_metrics scalar Resets all metrics for the current session Returns confirmation message [SELECT flock_reset_metrics();]

Überladene Funktionen

Diese Erweiterung fügt keine Funktionsüberladungen hinzu.

Hinzugefügte Typen

Diese Erweiterung fügt keine Typen hinzu.

Hinzugefügte Einstellungen

Diese Erweiterung fügt keine Einstellungen hinzu.