-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadintopgvector.js
57 lines (47 loc) · 1.42 KB
/
loadintopgvector.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
55
56
57
import { Document } from "@langchain/core/documents";
import { promises as fsp } from 'fs';
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama";
import { PGVectorStore } from "@langchain/community/vectorstores/pgvector";
const outputText = await fsp.readFile('./output.txt', 'utf8');
const splitter = new RecursiveCharacterTextSplitter({
chunkSize: 500,
chunkOverlap: 100,
});
const docOutput = await splitter.splitDocuments([
new Document({ pageContent: outputText }),
]);
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(docOutput);
const results = await pgvectorStore.similaritySearch("TimescaleDB", 1);
console.log(results);
await pgvectorStore.end();