-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpineconeWrite.js
72 lines (48 loc) · 1.88 KB
/
pineconeWrite.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import dotenv from 'dotenv';
dotenv.config();
import { Pinecone } from '@pinecone-database/pinecone';
import { PineconeStore } from "langchain/vectorstores/pinecone";
import { YoutubeLoader } from "langchain/document_loaders/web/youtube";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
// import { FaissStore } from "langchain/vectorstores/faiss";
// import { RetrievalQAChain } from "langchain/chains";
// import { ChatOpenAI } from "langchain/chat_models/openai";
// import readline from 'readline';
const PINECONE_API_KEY = process.env.PINECONE_API_KEY;
// console.log(PINECONE_API_KEY);
const loader = YoutubeLoader.createFromUrl("https://youtu.be/bZQun8Y4L2A", {
language: "en",
addVideoInfo: false,
});
// Load the data
const data = await loader.load();
const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 500,
chunkOverlap: 100,
});
// Split the the data into chunks
const splitDocs = await textSplitter.splitDocuments(data);
const pinecone = new Pinecone({
apiKey: PINECONE_API_KEY,
environment: 'gcp-starter'
})
const pineconeIndex = pinecone.Index("warmseat");
let response = await PineconeStore.fromDocuments(splitDocs, new OpenAIEmbeddings(), {
pineconeIndex,
maxConcurrency: 5, // Maximum number of batch requests to allow at once. Each batch is 1000 vectors.
});
console.log(response);
// const vectorStore = await FaissStore.fromDocuments(
// splitDocs,
// new OpenAIEmbeddings()
// );
// const model = new ChatOpenAI({ modelName: "gpt-3.5-turbo" });
// const chain = RetrievalQAChain.fromLLM(model, vectorStore.asRetriever());
// const response = await chain.call({
// query: "What's the summary of this talk?"
// });
// console.log(response);
// const list = await pinecone.listIndexes();
// await pinecone.describeIndex("warmseat");
// console.log(list);