Only this pageAll pages
Powered by GitBook
1 of 18

Integrations

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

OpenAI

Connect LangDB seamlessly using the OpenAI Client SDK for Python, Node.js, or cURL with minimal code changes.

LangDB seamlessly integrate with OpenAI Client.

1

Install OpenAI Client SDK

pip install openai
npm install openai
2

Add LangDB to your code

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="gpt-4o",  # Use the model
    messages=[{"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "gpt-4o-mini",  // Use the model
      messages: [{"role": "user","content": "Hello?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "gpt-4o",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
        "temperature": 0.8
    }'

Examples

All the provider and framework integrations supported on LangDB

Providers

Frameworks

OpenAI

Integration with OpenAI SDK

DeepSeek

Support for DeepSeek Models

Anthropic

Support for Anthropic Models

Gemini

Support for Gemini Models

Bedrock

Support for Bedrock Models

xAI

Support for xAI Models

TogetherAI

Support for TogetherAI Models

FireworksAI

Support for FireworksAI Models

DeepInfra

Support for DeepInfra Models

OpenRouter

Support for OpenRouter Models

Smithery

Support for MCP servers on smithery.ai

Vercel AI

Integration with Vercel AI SDK

LangChain

Integration with LangChain

CrewAI

Integration with CrewAI

LlamaIndex

Integration with LlamaIndex

Supabase

Integration with Supabase

mem0

Integration with Mem0

Cover

Vercel AI SDK

Connect LangDB to your Vercel AI projects using simple setup and start generating text with powerful LLM models instantl

LangDB integrates with applications built Vercel AI SDK.

1

Install Vercel AI SDK

npm i ai
npm i @langdb/vercel-provider
2

Add LangDB to your Code

import { generateText } from 'ai';
import { createLangDB } from '@langdb/vercel-provider';

const langdb = createLangDB({
  apiKey: process.env.LANGDB_API_KEY,
  projectId: 'your-project-id',
});

export async function generateTextExample() {
  const { text } = await generateText({
    model: langdb('openai/gpt-4o-mini'),
    prompt: 'Write a Python function that sorts a list:',
  });

  console.log(text);
}

LangChain

Connect LangDB to LangChain using OpenAI-compatible setup to enhance LLM workflows with full tracing and streamlined monitoring.

LangDB integrates seamlessly with popular libraries like LangChain, providing tracing support to capture detailed logs for workflows. Below is a complete example of using LangChain with LangDB.

1

Install LangChain

2

Add LangDB to your Code

Check out full examples in the .

LlamaIndex

Connect LangDB to LlamaIndex using OpenAI-compatible setup to enhance LLM workflows with full tracing and streamlined monitoring.

1

Install LlamaIndex

2

Add LangDB into your Code

Check out full examples in the .

Smithery

Integrate Smithery's EXA MCP server into LangDB to enhance AI workflows with real-time, tool-driven interactions via WebSocket.

LangDB supports MCP servers provided by .

This particular example is for .

Mem0

Use LangDB with Mem0 to store memories, embed text, and streamline LLM interactions across scalable applications.

LangDB seemlessly integrate with Mem0.

Check out the for more information.

1

Install mem0 Client

2

Add LangDB into your code

OpenRouter

Access OpenRouter models through LangDB’s API using OpenAI SDK

LangDB provides first class support for OpenRouter models.

You can use to run the xAI models.

Anthropic

Access Anthropic models through LangDB’s API using OpenAI SDK

LangDB provides first class support for Anthropic models.

You can use to run the Anthropic models.

CrewAI

Connect LangDB to CrewAI using OpenAI-compatible setup to enhance LLM workflows with full tracing and streamlined monitoring.

LangDB integrates seamlessly with popular libraries like CrewAI, providing tracing support to capture detailed logs for workflows. Below is a complete example of using CrewAI with LangDB.

1

Install CrewAI

2

Add LangDB to your Code

Check out full examples .

Gemini

Access Gemini models through LangDB’s API using OpenAI SDK

LangDB provides first class support for Gemini models.

You can use to run the Gemini models.

xAI

Access xAI models through LangDB’s API using OpenAI SDK

LangDB provides first class support for xAI models.

You can use to run the xAI models.

Bedrock

Access Amazon Bedrock models through LangDB’s API using OpenAI SDK

LangDB provides first class support for Bedrock models.

You can use to run the Bedrock models.

pip install langchain langchain-openai
from langchain_openai import ChatOpenAI

api_base = "https://api.us-east-1.langdb.ai"
api_key = "xxxx" # LangDB API Key
default_headers = {
    "x-project-id": "xxxxx",  ### LangDB Project ID
}
llm = ChatOpenAI(
    model_name='gpt-4o' , 
    temperature=0.3, 
    openai_api_base=api_base, 
    default_headers=default_headers,
    disable_streaming=True )

# Your LangChain Code here
samples
pip install llama-index openai
import os

from llama_index.llms import openai
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core import Settings
from llama_index.llms.openai import OpenAI

Settings.llm = OpenAI(
    base_url=os.getenv("OPENAI_API_BASE"),
    api_key=os.getenv("OPENAI_API_KEY"),
    model="gpt-4o-mini"
)

documents = SimpleDirectoryReader("data").load_data()
## Rest of your LlamaIndex
samples
from openai import OpenAI
from dotenv import load_dotenv
import os
import base64
import json
from urllib.parse import quote
load_dotenv()

def urlEncode(data_dict):
    """Convert dictionary to base64 and then URL encode it"""
    return quote(base64.b64encode(json.dumps(data_dict).encode()).decode())

config = {
    "exaApiKey": os.getenv("EXA_API_KEY")
}

config_str = urlEncode(config)
web_socket_url = "wss://your-mcp-server.com/ws"
extra_body = {
    "mcp_servers": [
        {
            "server_url": f"{web_socket_url}?config={config_str}",
            "type": "ws"
        }
    ]
}
client = OpenAI(
    api_key=os.getenv("LANGDB_API_KEY"),
    base_url=os.getenv("LANGDB_API_URL")

)
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "what is langdb?"}],
    extra_body = extra_body
)
print(response)
Smithery
EXA MCP server
pip install mem0ai python-dotenv
from mem0 import Memory
from dotenv import load_dotenv
load_dotenv()
import os
langdb_api_key = os.getenv("LANGDB_API_KEY")
langdb_project_id = os.getenv("LANGDB_PROJECT_ID")
base_url =  f"https://api.us-east-1.langdb.ai/{langdb_project_id}/v1"  

config = {
    "llm": {
        "provider": "openai",
        "config": {
            "model": "gpt-4o",
            "temperature": 0.0,
            "api_key": langdb_api_key,
            "openai_base_url": base_url,
        },
    },
    "embedder": {
        "provider": "openai",
        "config": {
            "model": "text-embedding-ada-002",
            "api_key": langdb_api_key,
            "openai_base_url": base_url,
        },
    }
}
m = Memory.from_config(config_dict=config)

result = m.add(
    "I like to take long walks on weekends.",
    user_id="alice",
    metadata={"category": "hobbies"},
)

print(result)
Mem0 documentation
pip install crewai
from crewai import LLM
project_id = "xxxx" ## LangDB Project ID
default_headers = {"x-project-id": project_id}
os.environ["OPENAI_API_KEY"] = (
    "xxxx"  ## LangDB API Key
)
llm_writer = LLM(model="gpt-4o-mini", 
                 base_url=api_base, 
                 extra_headers=default_headers)

# Your CrewAi code here
here
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "openrouter/aion-1.0-mini",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'
OpenAI SDK
from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="openrouter/aion-1.0-mini",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "openrouter/aion-1.0-mini",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "claude-3-5-sonnet-20240620",
        "messages": [
            {
                "role": "system",
                "content": "You are helpful assistant",
            },
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ]
    }'
OpenAI SDK
# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI
api_base = "https://api.us-east-1.langdb.ai"  # LangDB API base URL
api_key = "xxxxx"  # Replace with your LangDB token
default_headers = {"x-project-id": "xxxxx"} # LangDB Project ID
client = OpenAI(
    base_url=api_base,
    api_key=api_key,
)
response = client.chat.completions.create(
    model="claude-3-5-sonnet-20240620",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"}
    ],
    stream=False
)
print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
async function main() {
  const completion = await client.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }, {"role": "user", "content": "Hello"}],
    model: "claude-3-5-sonnet-20240620",
  }, { headers: defaultHeaders });
  console.log(completion.choices[0].message.content);
}
main();
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "gemini/gemini-1.5-flash-8b",
        "messages": [
            {
                "role": "system",
                "content": "You are helpful assistant",
            },
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ]
    }'
OpenAI SDK
# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI
api_base = "https://api.us-east-1.langdb.ai"  # LangDB API base URL
api_key = "xxxxx"  # Replace with your LangDB token
default_headers = {"x-project-id": "xxxxx"} # LangDB Project ID
client = OpenAI(
    base_url=api_base,
    api_key=api_key,
)
response = client.chat.completions.create(
    model="gemini/gemini-1.5-flash-8b",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"}
    ],
    stream=False
)
print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
async function main() {
  const completion = await client.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }, {"role": "user", "content": "Hello"}],
    model: "gemini/gemini-1.5-flash-8b",
  }, { headers: defaultHeaders });
  console.log(completion.choices[0].message.content);
}
main();
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "xai/grok-2",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'
OpenAI SDK
from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="xai/grok-2",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "xai/grok-2",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "bedrock/command-r-v1:0",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'
OpenAI SDK
from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="bedrock/command-r-v1:0",  # Use the model
    messages=[{"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "bedrock/command-r-v1:0",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code

TogetherAI

Access TogetherAI models through LangDB’s API using OpenAI SDK

LangDB provides first class support for TogetherAI opensource hosted models.

You can use OpenAI SDK to run the xAI models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="togetherai/DeepSeek-V3",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "togetherai/DeepSeek-V3",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "togetherai/DeepSeek-V3",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

FireworksAI

Access FireworksAI models through LangDB’s API using OpenAI SDK

LangDB provides first class support for FireworksAI opensource hosted models.

You can use OpenAI SDK to run the xAI models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="fireworksai/deepseek-r1",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "fireworksai/deepseek-r1",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "fireworksai/deepseek-r1",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

DeepInfra

Access DeepInfra models through LangDB’s API using OpenAI SDK

LangDB provides first class support for DeepInfra opensource hosted models.

You can use OpenAI SDK to run the xAI models.

from openai import OpenAI
client = OpenAI(
    base_url="https://api.us-east-1.langdb.ai"  # LangDB API base URL,
    api_key=api_key,  # Replace with your LangDB token
)
# Make the API call to LangDB's Completions API
response = client.chat.completions.create(
    model="deepinfra/phi-4",  # Use the model
    messages=[{"role": "user", "content": "Hello!"}],  
    extra_headers={"x-project-id": "xxxxx"} # LangDB Project ID
)
import { OpenAI } from 'openai'; // Assuming you're using the OpenAI Node.js SDK
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
const response = await client.chat.completions.create({
      model: "deepinfra/phi-4",  // Use the model
      messages: [{"role": "user","content": "What are the earnings of Apple in 2022?"}], 
    }, { headers: defaultHeaders });
// Rest of Your Code\
curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "deepinfra/phi-4",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ],
    }'

DeepSeek

Access DeepSeek models through LangDB’s API using OpenAI SDK, enabling fast, reliable AI performance across platforms.

LangDB provides first class support for DeepSeek AI’s models.

You can use to run the deepseek models.

curl "https://api.us-east-1.langdb.ai/v1/chat/completions" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LANGDB_API_KEY" \
    -X "X-Project-Id: $Project_ID" \
    -d '{
        "model": "deepseek-reasoner",
        "messages": [
            {
                "role": "user",
                "content": "Write a haiku about recursion in programming."
            }
        ]
    }'
OpenAI SDK
# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI
api_base = "https://api.us-east-1.langdb.ai"  # LangDB API base URL
api_key = "xxxxx"  # Replace with your LangDB token
default_headers = {"x-project-id": "xxxxx"} # LangDB Project ID
client = OpenAI(
    base_url=api_base,
    api_key=api_key,
)
response = client.chat.completions.create(
    model="deepseek-reasoner",
    messages=[
        {"role": "system", "content": "You are a helpful assistant"},
        {"role": "user", "content": "Hello"}
    ],
    stream=False
)
print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
const apiBase = "https://api.us-east-1.langdb.ai";  // LangDB API base URL
const apiKey = "LANGDB_API_KEY";  // Replace with your LangDB token
const defaultHeaders = { "x-project-id": "xxxx" };  // LangDB Project ID
const client = new OpenAI({
  baseURL: apiBase,
  apiKey: apiKey,
});
async function main() {
  const completion = await client.chat.completions.create({
    messages: [{ role: "system", content: "You are a helpful assistant." }, {"role": "user", "content": "Hello"}],
    model: "deepseek-reasoner",
  }, { headers: defaultHeaders });
  console.log(completion.choices[0].message.content);
}
main();

Supabase

Connect LangDB to LangChain using OpenAI-compatible setup to generate embeddings and store them in Supabase for efficient data retrieval.

LangDB integrates AI models like OpenAI to generate embeddings and store them in Supabase for efficient data retrieval.

Preparing Database

1

Create a Supabase Project

Go to Supabase and create a new project.

2

Enable PgVector

create extension vector;
3

Create a table to store Embeddings

create table embeddings (
  id bigserial primary key,
  content text,
  embedding vector(1536)
);

Generating and Storing Embeddings

1

Install Libraries

pip install openai python-dotenv supabase
2

Generate Embeddings

from openai import OpenAI
from dotenv import load_dotenv
from supabase import create_client, Client
import os

load_dotenv()
api_key = os.getenv("LANGDB_API_KEY")
project_id = os.getenv("LANGDB_PROJECT_ID")
base_url = f"https://api.us-east-1.langdb.ai/{project_id}/v1"


client = OpenAI(
    base_url=base_url,
    api_key=api_key,
)

text = "Hello LangDB"
response = client.embeddings.create(
    model="text-embedding-ada-002",
    input=text,
)

embedding = response.data[0].embedding
3

Store in Supabase

# # Store in Supabase
result = supabase.table('embeddings').insert({
    "content": text,
    "embedding": embedding
}).execute()

Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover
Cover