0

I need some help with a NextJS App with Langchain. I also use the Vercel AI SDK and got an API Route /api/chat. Here is how my content looks like:

import { config } from "dotenv";

config();

import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { FaissStore } from "langchain/vectorstores/faiss";
import { AIChatMessage, HumanChatMessage } from "langchain/schema";

export const runtime = "edge";

export async function POST(req: Request) {
  const { messages } = await req.json();

  const embeddings = new OpenAIEmbeddings();
  const vectorStore = await FaissStore.load("./", embeddings); # creates error

 ... # Rest

the load function of FassStore uses the fs module under the hood. It results in Module not found: Can't resolve 'fs'.

NextJS API routes should be able to use fs, see here: https://github.com/vercel/next.js/discussions/32236

I also came across this: Module not found: Can't resolve 'fs' - NextJS . This seems not to be a viable option.

Does anyone know what I am doing wrong here or how to fix that? Thank you :-)

Data Mastery
  • 1,555
  • 4
  • 18
  • 60

0 Answers0