-
Notifications
You must be signed in to change notification settings - Fork 43
/
LangChain.js
54 lines (49 loc) · 1.67 KB
/
LangChain.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Milvus } from 'langchain/vectorstores/milvus';
import { OpenAIEmbeddings } from 'langchain/embeddings/openai';
const address = `localhot:19530`; // or your zilliz cloud endpoint
const ssl = false; // set it to true if you are using zilliz cloud
const token = 'username:passowrd or apikey'; // your zilliz cloud apikey or username:password
const openAIApiKey = ``;
const collectionName = 'books';
// text sample from Godel, Escher, Bach
const vectorStore = await Milvus.fromTexts(
[
'Tortoise: Labyrinth? Labyrinth? Could it Are we in the notorious Little\
Harmonic Labyrinth of the dreaded Majotaur?',
'Achilles: Yiikes! What is that?',
'Tortoise: They say-although I person never believed it myself-that an I\
Majotaur has created a tiny labyrinth sits in a pit in the middle of\
it, waiting innocent victims to get lost in its fears complexity.\
Then, when they wander and dazed into the center, he laughs and\
laughs at them-so hard, that he laughs them to death!',
'Achilles: Oh, no!',
"Tortoise: But it's only a myth. Courage, Achilles.",
],
[{ id: 2 }, { id: 1 }, { id: 3 }, { id: 4 }, { id: 5 }],
new OpenAIEmbeddings({
openAIApiKey,
}),
{
collectionName,
vectorField: 'vectors',
clientConfig: {
address,
ssl,
token,
},
}
);
const response = await vectorStore.similaritySearch('scared', 2);
console.log('response', response);
/*
response [
Document {
pageContent: 'Achilles: Oh, no!',
metadata: { id: 442006163964035500 }
},
Document {
pageContent: 'Achilles: Yiikes! What is that?',
metadata: { id: 442006163964035460 }
}
]
*/