scrimba
AI Engineering
Embeddings and Vector Databases
Vector databases
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

AboutCommentsNotes
Vector databases
Expand for more info
index.js
run
preview
console
import openai 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:
"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
, ...]
}
,
{content:
"Mysteries of the deep: exploring uncharted ocean caves."
, embedding:
[
0.024133362
,
-0.02058745
,
0.017835401
,
-0.011233127
,
-0.024715526
,
0.011616826
,
-0.032971676
,
-0.012357763
,
-0.008070916
,
-0.0018275331
,
0.012986235
,
0.018563107
,
0.0001506061
,
-0.02058745
,
0.0003065873
,
-0.011312513
,
0.024503829
,
-0.01075681
,
0.016327066
,
-0.021169616
,
-0.004465466
,
0.014699652
,
0.015811056
,
-0.010736964
,
-0.010882505
,
-0.0144218
,
0.00038287233
,
-0.018496951
,
0.0084215375
,
-0.0136940945
, ...]
}
,
{content:
"Rediscovering lost melodies: the rebirth of vinyl culture."
, embedding:
[
-0.013441176
,
-0.014023848
,
-0.0015915876
,
-0.019545985
,
-0.020367023
,
-0.00024664227
,
-0.013560358
,
-0.009574355
,
-0.025743494
,
0.0033205664
,
0.010388771
,
0.018433612
,
-0.0017264959
,
0.008415633
,
-0.018433612
,
-0.003595349
,
0.030987538
,
0.01393115
,
0.02823309
,
0.00798525
,
-0.016870992
,
0.002208193
,
0.004423008
,
-0.0062438566
,
0.0026749927
,
-0.010262967
,
0.009395581
,
-0.0183674
,
0.03829742
,
0.014460851
, ...]
}
,
{content:
"Tales from the tech frontier: decoding AI ethics."
, embedding:
[
0.008981468
,
-0.0311228
,
0.0215583
,
-0.023126934
,
0.008238797
,
0.014700734
,
-0.022377321
,
0.022877064
,
-0.012549069
,
-0.034371123
,
0.023654439
,
0.020059075
,
0.0060246633
,
-0.028790673
,
-0.0020145837
,
-0.0096547315
,
0.014298164
,
-0.00656258
,
0.021766527
,
-0.018296098
,
-0.038035892
,
0.029873446
,
-0.012007682
,
-0.000012580303
,
-0.007648824
,
-0.013874772
,
0.021447247
,
-0.024362406
,
0.0021759586
,
-0.016838517
, ...]
}
,
{content:
"Jazz under stars: a night in New Orleans' music scene."
, embedding:
[
0.0020661303
,
-0.015001259
,
0.02385187
,
-0.021652387
,
0.01122131
,
0.006394303
,
0.0019064375
,
-0.0006589392
,
-0.025405996
,
-0.011063264
,
-0.00013787922
,
0.003193859
,
0.005781872
,
-0.013697375
,
-0.006947466
,
-0.027473772
,
0.02310115
,
-0.01360518
,
0.017306106
,
-0.022310914
,
-0.006476619
,
0.008606955
,
0.012933482
,
0.018399261
,
0.004096042
,
-0.0010635221
,
0.011069849
,
-0.015896857
,
0.009700112
,
0.0053538294
, ...]
}
,
"Embedding complete!"
,
/index.html
-3:00