DEV Community

parmarjatin4911@gmail.com
parmarjatin4911@gmail.com

Posted on

Embeddings and Vector Database

Embeddings and Vector Database

Creating an Embedding using OpenAI API for testing (Postman):
Enter fullscreen mode Exit fullscreen mode

POST Request:
URL: api.openai.com/version1/embeddings
Headers:

  • Content-Type: application/json
  • Authorization: Bearer
    Body:
    {
    "model": "ada002",
    "input": "hello world"
    }

    Creating a Workspace and Database in SingleStore:

Create a workspace with the desired cloud platform and region:

  • Workspace Name: open AI Vector database
  • Cloud Platform: AWS (or Google/Microsoft Azure)
  • Region: US West (or the desired region)

Create a database with a table for embeddings:

  • Database Name: open AI database
  • Table Columns:

    • Text (type: text)
    • Vector (type: blob)

    SQL Query to add to the Vector Database in SingleStore:

INSERT INTO myvectortable (text, vector) VALUES ('Hello World', JSON_ARRAY_PACK('[***]'));

SQL Query to Search the Vector Database in SingleStore:
Enter fullscreen mode Exit fullscreen mode

select text, dot_product (vector, JSON_ARRAY_PACK("[***]")) as score from myvectortable order by score desc limit 5;

Fetching Embeddings using JavaScript (Node.js):
Enter fullscreen mode Exit fullscreen mode

JavaScript Code:
// Assuming fetch is available (for modern browsers or Node.js with appropriate polyfills)
const response = await fetch('api.openai.com/version1/embeddings', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ',
},
body: JSON.stringify({
model: 'ada002',
input: 'hello world',
}),
});
const data = await response.json();
console.log(data);

Please note t

hat some specific values like and are placeholders and should be replaced with actual API keys and embedding values as needed in your implementation. Also, some parts of the transcript might be cut off or incomplete, so there may be additional commands that were not provided in the given text.

Top comments (0)