-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (25 loc) · 1 KB
/
index.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
import 'dotenv/config';
import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf";
import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
import { OllamaEmbeddings } from "@langchain/ollama";
import { Chroma } from "@langchain/community/vectorstores/chroma";
const loader = new PDFLoader("./news.pdf");
const docs = await loader.load();
const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 1000,
chunkOverlap: 200,
});
const allSplits = await textSplitter.splitDocuments(docs);
const embeddings = new OllamaEmbeddings({
// apiKey: process.env.OPENAI_API_KEY,
model: "mxbai-embed-large:latest"
});
const vectorStore = new Chroma(embeddings, {
collectionName: "a-new-test-collection2",
url: "http://0.0.0.0:8000",
});
await vectorStore.addDocuments(allSplits);
const results2 = await vectorStore.similaritySearchWithScore(
"What Purdue SAFE-RWSL surveillance system built to prevent airport runway incursions?"
);
console.log(results2[0]);