Models
Picking your favorite model is the final step in creating a RAG pipeline. LangDB allows you to plug in your desired LLM model and use it for generating responses. Currently, only OpenAI models are supported. As is with prompts, creating a model is as simple as composing a SQL query. After model creation, it can be run as a SQL function to generate responses based on the input text.
Creating a Model
We will be using the OpenAi provider to create completions model and embedding model. More details in Providers section.
To create a model, you need to use the CREATE MODEL
SQL command.
Competions Model
CREATE MODEL sentiment_analysis(
input
) USING openai(model_name = 'gpt-4o-mini')
PROMPT ( system "Classify the text into neutral, negative, or positive
Text: {{input}}
Sentiment:" )
SETTINGS retries = 2;
Embedding Model
CREATE EMBEDDING MODEL generate_embeddings
USING openai(model='text-embedding-ada-002', encoding_format='float')
This is the basic syntax for creating a model. For more advanced options, you can refer to the CREATE MODEL syntax.
Using a Model
Once you have created a model, you can use it to generate responses. The model can be run as a SQL function to generate responses based on the input text.
SELECT * FROM sentiment_analysis('This is a horrible TV show. The acting is terrible and the plot is boring.');
Similarly for embeddings model
SELECT * FROM generate_embeddings('This is a horrible TV show. The acting is terrible and the plot is boring.');
Deleting a Model
If you want to delete a model, you can use the DROP MODEL
SQL command. Additionally, you can also specify the CASCADE
keyword at the end to remove dependent prompts.
DROP MODEL sentiment_analysis;