scrimba
AI Engineering
Embeddings and Vector Databases
Set up your vector database with Supabase
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

To see this lesson you need to be logged in. Joining Scrimba is free and gives you access to 20+ courses.Sign up
Set up your vector database with Supabase
AboutCommentsNotes
Set up your vector database with Supabase
Expand for more info
index.js
run
preview
console
import { openai, supabase } from './config.js';

const content = [
"Beyond Mars: speculating life on distant planets.",
"Jazz under stars: a night in New Orleans' music scene.",
"Mysteries of the deep: exploring uncharted ocean caves.",
"Rediscovering lost melodies: the rebirth of vinyl culture.",
"Tales from the tech frontier: decoding AI ethics.",
];

async function main(input) {
await Promise.all(
input.map( async (textChunk) => {
const embeddingResponse = await openai.embeddings.create({
model: "text-embedding-ada-002",
input: textChunk
});
const data = {
content: textChunk,
embedding: embeddingResponse.data[0].embedding
}
console.log(data);
})
);
console.log('Embedding complete!');
}
main(content);
Console
{content:
"Tales from the tech frontier: decoding AI ethics."
, embedding:
[
0.008923522
,
-0.031444132
,
0.021985892
,
-0.023360878
,
0.0074721477
,
0.014749853
,
-0.022860883
,
0.022819217
,
-0.0125693185
,
-0.034471877
,
0.023416433
,
0.020291464
,
0.005756887
,
-0.028277496
,
-0.0018281067
,
-0.009055465
,
0.014624854
,
-0.0070103467
,
0.022319222
,
-0.018208152
,
-0.0377774
,
0.029721925
,
-0.012423487
,
-0.00057421305
,
-0.007944365
,
-0.013722085
,
0.021402564
,
-0.024194203
,
0.0023454628
,
-0.016652612
, ...]
}
,
{content:
"Rediscovering lost melodies: the rebirth of vinyl culture."
, embedding:
[
-0.013356166
,
-0.014011724
,
-0.0016157187
,
-0.01952106
,
-0.020328918
,
-0.0002754254
,
-0.013574686
,
-0.009528767
,
-0.025705818
,
0.0032430254
,
0.010303518
,
0.018488059
,
-0.0016951802
,
0.00843617
,
-0.018448329
,
-0.0036386778
,
0.030990014
,
0.013932263
,
0.028261833
,
0.007966023
,
-0.016898828
,
0.0021686389
,
0.0044630915
,
-0.0063105733
,
0.00267024
,
-0.010270408
,
0.009475793
,
-0.018408598
,
0.038300477
,
0.014462006
, ...]
}
,
{content:
"Mysteries of the deep: exploring uncharted ocean caves."
, embedding:
[
0.02407598
,
-0.020581719
,
0.017855138
,
-0.01121075
,
-0.02473777
,
0.01165415
,
-0.032983694
,
-0.012309324
,
-0.008020914
,
-0.0018265449
,
0.012938026
,
0.018596344
,
0.00019802045
,
-0.020661134
,
0.0002868453
,
-0.0113497265
,
0.02457894
,
-0.010787203
,
0.016372724
,
-0.021190567
,
-0.0044505484
,
0.014585887
,
0.01584329
,
-0.010793821
,
-0.010846765
,
-0.014493236
,
0.00028974065
,
-0.018490458
,
0.008424607
,
-0.013712322
, ...]
}
,
{content:
"Jazz under stars: a night in New Orleans' music scene."
, embedding:
[
0.0020358858
,
-0.014957259
,
0.023857882
,
-0.021724893
,
0.011296944
,
0.0063890936
,
0.0018926989
,
-0.00066902797
,
-0.025437875
,
-0.011125779
,
-0.0001403066
,
0.003202776
,
0.005773555
,
-0.013706433
,
-0.006958549
,
-0.027491864
,
0.023067886
,
-0.013587933
,
0.017248249
,
-0.022370055
,
-0.0064812596
,
0.008538541
,
0.012949353
,
0.018433243
,
0.0039993552
,
-0.0010689634
,
0.011086279
,
-0.015905255
,
0.009736702
,
0.0053653903
, ...]
}
,
{content:
"Beyond Mars: speculating life on distant planets."
, embedding:
[
0.010831459
,
-0.017285094
,
-0.013020372
,
-0.018908482
,
-0.008409684
,
0.014916543
,
-0.02143671
,
-0.006210791
,
-0.014264527
,
0.010944564
,
0.010558677
,
0.018243158
,
-0.013772188
,
0.0031819076
,
0.007098997
,
-0.005232766
,
0.029966151
,
-0.0027261612
,
0.033665348
,
-0.0061608916
,
0.023645582
,
-0.00022496236
,
0.006972586
,
-0.003476313
,
0.002443399
,
0.008283272
,
0.023166548
,
-0.015954448
,
0.0037723817
,
0.00215731
, ...]
}
,
"Embedding complete!"
,
/index.html
-3:13