-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpgvector_setup.js
45 lines (38 loc) · 1.07 KB
/
pgvector_setup.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
import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama";
import { PGVectorStore } from "@langchain/community/vectorstores/pgvector";
const config = {
postgresConnectionOptions: {
type: "postgres",
host: "localhost",
port: 5432,
user: "postgres",
password: "password",
database: "jaxnodevector",
},
tableName: "vectordocs",
columns: {
idColumnName: "id",
vectorColumnName: "vector",
contentColumnName: "content",
metadataColumnName: "metadata",
},
};
const embeddings = new OllamaEmbeddings({
model: "llama2", // default value
baseUrl: "http://localhost:11434", // default value
requestOptions: {
useMMap: true,
numThread: 6,
numGpu: 1,
},
});
const pgvectorStore = await PGVectorStore.initialize(
embeddings,
config
);
await pgvectorStore.addDocuments([
{ pageContent: "what's this", metadata: { a: 2 } },
{ pageContent: "Cat drinks milk", metadata: { a: 1 } },
]);
const results = await pgvectorStore.similaritySearch("water", 1);
console.log(results);