-
From the line of code below, I am trying to get the path to the restaurant.txt file which is located under from pages/api/indexes.js
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
🤖 Hello, Yes, you can use the Faiss vector store with Next.js. The issue you're facing might be due to the relative path you're using to load the Here's how you can modify your code: const loader = new TextLoader("pages/api/restaurant.txt"); Also, when you save the vector store, you're saving it to the root directory ( await vectorStore.save("pages/api"); Here's the complete modified code: const { OpenAIEmbeddings } = require("langchain/embeddings/openai");
const { FaissStore } = require("langchain/vectorstores/faiss");
const { CharacterTextSplitter } = require("langchain/text_splitter");
const { TextLoader } = require("langchain/document_loaders/fs/text");
const indexes = async (req, res) => {
const loader = new TextLoader("pages/api/restaurant.txt");
console.log(loader);
const docs = await loader.load();
const splitter = new CharacterTextSplitter({
chunkSize: 200,
chunkOverlap: 50,
});
const documents = await splitter.splitDocuments(docs);
console.log(documents);
const embeddings = new OpenAIEmbeddings();
const vectorStore = await FaissStore.fromDocuments(documents, embeddings);
await vectorStore.save("pages/api");
res.status(200).json({ ok: ok });
};
module.exports = { indexes }; Please try this and let me know if it works for you. If you're still facing issues, please provide more details about the error or unexpected behavior you're experiencing. Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Needed to npm faiss-node PLUS.. Integrated this code to another file because NEXT.js wouldn't run the |
Beta Was this translation helpful? Give feedback.
Needed to npm faiss-node
PLUS..
Integrated this code to another file because NEXT.js wouldn't run the
node pages/api/indexes.js
command