-
Notifications
You must be signed in to change notification settings - Fork 8
/
ingest.ts
29 lines (25 loc) · 913 Bytes
/
ingest.ts
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
import { HNSWLib } from "langchain/vectorstores";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { TextLoader } from "langchain/document_loaders";
const FILENAME = "limits2023.md";
export const run = async () => {
const loader = new TextLoader(FILENAME);
const rawDocs = await loader.load();
console.log("Loader created.");
/* Split the text into chunks */
const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 1000,
chunkOverlap: 200,
});
const docs = await textSplitter.splitDocuments(rawDocs);
console.log("Docs splitted.");
console.log("Creating vector store...");
/* Create the vectorstore */
const vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings());
await vectorStore.save("data");
};
(async () => {
await run();
console.log("done");
})();