-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadPDFintoVectorStore.js
44 lines (37 loc) · 1.03 KB
/
loadPDFintoVectorStore.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
import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama";
import { PGVectorStore } from "@langchain/community/vectorstores/pgvector";
import { PDFLoader } from "langchain/document_loaders/fs/pdf";
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
);
const loader = new PDFLoader("./wstg-v4.2.pdf");
const docs = await loader.load();
await pgvectorStore.addDocuments(docs);
pgvectorStore.end();