LLM & RAG extension to combine analytics and semantic analysis
Installing and Loading
INSTALL flockmtl FROM community;
LOAD flockmtl;
Example
-- 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/flockmtl/docs/what-is-flockmtl/). 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', {'context_window': 128000, 'max_output_tokens': 16400});
-- Summarize text and pass it as parameter
D SELECT llm_complete({'model_name': 'summarizer-model'}, {'prompt_name': 'summarize'}, {'text': 'We support more functions and approaches to combine relational analytics and semantic analysis. Check our repo for documentation and examples.'});
About flockmtl
FlockMTL is an experimental DuckDB extension that enables seamless integration of large language models (LLMs) and retrieval-augmented generation (RAG) directly within SQL.
It introduces MODEL
and PROMPT
objects as first-class SQL entities, making it easy to define, manage, and reuse LLM interactions. Core functions like llm_complete
, llm_filter
, and llm_rerank
allow you to perform generation, semantic filtering, and ranking—all from SQL.
FlockMTL is designed for rapid prototyping of LLM-based analytics and is optimized with batching and caching features for better performance.
📄 For more details and examples, see the FlockMTL documentation.
Note: FlockMTL is part of ongoing research by the Data & AI Systems (DAIS) Laboratory @ Polytechnique Montréal. It is under active development, and some features may evolve. Feedback and contributions are welcome!
Added Functions
function_name | function_type | description | comment | examples |
---|---|---|---|---|
fusion_combanz | scalar | NULL | NULL | |
fusion_combmed | scalar | NULL | NULL | |
fusion_combmnz | scalar | NULL | NULL | |
fusion_combsum | scalar | NULL | NULL | |
fusion_rrf | scalar | NULL | NULL | |
llm_complete | scalar | NULL | NULL | |
llm_complete_json | scalar | NULL | NULL | |
llm_embedding | scalar | NULL | NULL | |
llm_filter | scalar | NULL | NULL | |
llm_first | aggregate | NULL | NULL | |
llm_last | aggregate | NULL | NULL | |
llm_reduce | aggregate | NULL | NULL | |
llm_reduce_json | aggregate | NULL | NULL | |
llm_rerank | aggregate | NULL | NULL |