flockmtl
LLM- und RAG-Erweiterung zur Kombination von Analytik und semantischer Analyse
Maintainer: anasdorbani, queryproc
Installation und Laden
INSTALL flockmtl FROM community;LOAD flockmtl;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/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 modelsD GET PROMPTS;D GET MODELS;
-- Create a new prompt for summarizing textD CREATE PROMPT('summarize', 'summarize the text into 1 word: {{text}}');
-- Create a variable name for the model to do the summarizingD CREATE MODEL('summarizer-model', 'gpt-4o', 'openai');
-- Summarize text and pass it as parameterD 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 flockmtl
FlockMTL 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.
FlockMTL ist für das schnelle Prototyping LLM-basierter Analytik ausgelegt und mit Batching- und Caching-Funktionen für bessere Leistung optimiert.
📄 Weitere Details und Beispiele finden Sie in der FlockMTL-Dokumentation.
Hinweis: FlockMTL 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 a defined prompt and model | [SELECT llm_complete({‘model_name’: ‘default’}, {‘prompt_name’: ‘hello-world’});] |
| llm_filter | scalar | Filters data based on language model evaluations | returning boolean values | [SELECT * FROM data WHERE llm_filter({‘model_name’: ‘default’}, {‘prompt_name’: ‘is_relevant’, ‘context_columns’: [{‘data’: content}]});] |
| llm_embedding | scalar | Generates embeddings for input text | Useful for semantic similarity tasks | [SELECT llm_embedding({‘model_name’: ‘default’}, {‘context_columns’: [{‘data’: ‘Sample text’}]});] |
| llm_reduce | aggregate | Aggregates multiple inputs into a single output using a language model | Summarizes or combines multiple rows | [SELECT llm_reduce({‘model_name’: ‘default’}, {‘prompt_name’: ‘summarize’, ‘context_columns’: [{‘data’: content}]}) FROM documents;] |
| llm_rerank | aggregate | Reorders query results based on relevance scores from a language model | Enhances result relevance in search applications | [SELECT llm_rerank({‘model_name’: ‘default’}, {‘prompt_name’: ‘rank_relevance’, ‘context_columns’: [{‘data’: content}]}) FROM search_results;] |
| llm_first | aggregate | Selects the top-ranked result after reranking | Retrieves the most relevant item | [SELECT llm_first({‘model_name’: ‘default’}, {‘prompt_name’: ‘rank_relevance’, ‘context_columns’: [{‘data’: content}]}) FROM search_results;] |
| llm_last | aggregate | Selects the bottom-ranked result after reranking | Retrieves the least relevant item | [SELECT llm_last({‘model_name’: ‘default’}, {‘prompt_name’: ‘rank_relevance’, ‘context_columns’: [{‘data’: content}]}) FROM search_results;] |
| fusion_rrf | scalar | Implements Reciprocal Rank Fusion (RRF) to combine rankings | Combines rankings from multiple scoring systems | [SELECT fusion_rrf(score1, score2) FROM combined_scores;] |
| fusion_combsum | scalar | Sums normalized scores from different scoring systems | Useful for aggregating scores from various models | [SELECT fusion_combsum(score1, score2) FROM combined_scores;] |
| fusion_combmnz | scalar | Sums normalized scores and multiplies by the hit count | Enhances the impact of frequently occurring items | [SELECT fusion_combmnz(score1, score2) FROM combined_scores;] |
| fusion_combmed | scalar | Computes the median of normalized scores | Reduces the effect of outliers in combined scores | [SELECT fusion_combmed(score1, score2) FROM combined_scores;] |
| fusion_combanz | scalar | Calculates the average of normalized scores | Provides a balanced aggregation of scores | [SELECT fusion_combanz(score1, score2) FROM combined_scores;] |