forked from dexaai/dexter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.ts
41 lines (35 loc) · 1.31 KB
/
basic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'dotenv/config';
import { EmbeddingModel } from '@dexaai/dexter/model';
import { PineconeDatastore } from '@dexaai/dexter/datastore/pinecone';
/**
* npx tsx examples/basic.ts
*/
async function main() {
// Create a default OpenAI 'text-embedding-ada-002' embedding model
// Requires process.env.OPENAI_API_KEY
const embeddingModel = new EmbeddingModel();
// Connect to a Pinecone datastore which uses our OpenAI embedding model
// Requires process.env.PINECONE_API_KEY
// Requires process.env.PINECONE_BASE_URL
const store = new PineconeDatastore({
contentKey: 'content',
embeddingModel,
});
// Upsert some docs
await store.upsert([
{ id: '1', metadata: { content: 'cat' } },
{ id: '2', metadata: { content: 'dog' } },
{ id: '3', metadata: { content: 'whale' } },
{ id: '4', metadata: { content: 'shark' } },
{ id: '5', metadata: { content: 'computer' } },
{ id: '6', metadata: { content: 'laptop' } },
{ id: '7', metadata: { content: 'phone' } },
{ id: '8', metadata: { content: 'tablet' } },
]);
// Make some semantic queries
const result = await store.query({ query: 'dolphin' });
console.log(JSON.stringify(result, null, 2));
const result2 = await store.query({ query: 'keyboard', topK: 3 });
console.log(JSON.stringify(result2, null, 2));
}
main();