Below is the code. I am using langchain DirectoryLoader to load the data directory in which three txt files are there. I think rest of the code is very simple. Please help me because i have tried creating different dimensions of indices but doesn’t worked.
const model = new OpenAI({
openAIApiKey: apiKey,
temperature: 0.9,
});
const embeddings = new OpenAIEmbeddings();
const loader = new DirectoryLoader(
'./data',
{
".txt": (path) => new TextLoader(path),
}
);
loader.load().then( async (docs)=>{
const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 1000 });
const texts = await textSplitter.splitDocuments(docs)
console.log(texts.length)
const pinecone = new PineconeClient();
await pinecone.init({
apiKey: process.env.PINECONE_API_KEY,
environment: process.env.PINECONE_ENVIRONMENT,
})
const pineconeIndex = pinecone.Index(process.env.PINECONE_INDEX_NAME);
const newTexts = texts.map((text)=>{
return text.pageContent
})
const vectorStore = await PineconeStore.fromDocuments(texts, embeddings, { pineconeIndex:pineconeIndex});
console.log(vectorStore);
}).catch(err => {
throw err;
})