RAG Chatbot with JavaScript, LangChain.js, Next.js, Vercel, OpenAI
Retrieval-Augmented Generation or RAG is when you change the output of a Large Language Model or LLM, by providing the model more context alongside a user's input. That way the model can use its ability to generate text along with the extra context to provide accurate answers to users questions.
RAG is useful because it allows you to provide more context to a model, which can help the model provide more accurate answers. This is useful because it can help the model provide more accurate answers to questions, which can be useful in a variety of applications.
List of benefits:
- Cost effective
- Cut off dates
- Information does not exist
Vector embedding is a popular technique to represent information in a format that can be easily processed by algorithms, especially deep learning models. This information can be text, pictures, video and audio.
- Node v20.x+
- OpenAI account
- DataStax Vector Database
Go to https://astra.datastax.com/ and create a new serverless vector database in the form.
Database name: dbf1
Create an account at https://platform.openai.com/settings/organization/api-keys and get your API key.
We will work with OpenAI models:
gpt-4modeltext-embedding-3-smallembeddings model
npx create-next-app@latest rag-chatbot-nextjs-f1gpt
Options:
✔ Would you like to use TypeScript? … Yes
✔ Would you like to use ESLint? … Yes
✔ Would you like to use Tailwind CSS? … No
✔ Would you like your code inside a `src/` directory? … No
✔ Would you like to use App Router? (recommended) … No
✔ Would you like to use Turbopack for `next dev`? … No
✔ Would you like to customize the import alias (`@/*` by default)? › NoDependencies:
npm i dotenv
npm i openai
npm i langchain
npm i @datastax/astra-db-ts
npm i --save-dev ts-node
npm i @langchain/community
npm i puppeteer
npm i ai@3.4Load additional articles to vector database to augment knowledge base.
npm run seedRun chat application:
npm run dev