Elffuss BraidHub

kikocis/lancedb public

bbc8a2ecbe2c · 2.6 KiBRenderedRawPermalink
1# LanceDB Chatbot - Vercel Next.js Template
2Use an AI chatbot with website context retrieved from a vector store like LanceDB. LanceDB is lightweight and can be embedded directly into Next.js, with data stored on-prem.
3
4## One click deploy on Vercel
5[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Flancedb%2Flancedb-vercel-chatbot&env=OPENAI_API_KEY&envDescription=OpenAI%20API%20Key%20for%20chat%20completion.&project-name=lancedb-vercel-chatbot&repository-name=lancedb-vercel-chatbot&demo-title=LanceDB%20Chatbot%20Demo&demo-description=Demo%20website%20chatbot%20with%20LanceDB.&demo-url=https%3A%2F%2Flancedb.vercel.app&demo-image=https%3A%2F%2Fi.imgur.com%2FazVJtvr.png)
6
7![Demo website landing page](../assets/vercel-template.gif)
8
9## Development
10
11First, rename `.env.example` to `.env.local`, and fill out `OPENAI_API_KEY` with your OpenAI API key. You can get one [here](https://openai.com/blog/openai-api).
12
13Run the development server:
14
15```bash
16npm run dev
17# or
18yarn dev
19# or
20pnpm dev
21```
22
23Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
24
25This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
26
27## Learn More
28
29To learn more about LanceDB or Next.js, take a look at the following resources:
30
31- [LanceDB Documentation](https://lancedb.github.io/lancedb/) - learn about LanceDB, the developer-friendly serverless vector database.
32- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
33- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
34
35## LanceDB on Next.js and Vercel
36
37FYI: these configurations have been pre-implemented in this template.
38
39Since LanceDB contains a prebuilt Node binary, you must configure `next.config.js` to exclude it from webpack. This is required for both using Next.js and deploying on Vercel.
40```js
41/** @type {import('next').NextConfig} */
42module.exports = ({
43 webpack(config) {
44 config.externals.push({ vectordb: 'vectordb' })
45 return config;
46 }
47})
48```
49
50To deploy on Vercel, we need to make sure that the NodeJS runtime static file analysis for Vercel can find the binary, since LanceDB uses dynamic imports by default. We can do this by modifying `package.json` in the `scripts` section.
51```json
52{
53 ...
54 "scripts": {
55 ...
56 "vercel-build": "sed -i 's/nativeLib = require(`@lancedb\\/vectordb-\\${currentTarget()}`);/nativeLib = require(`@lancedb\\/vectordb-linux-x64-gnu`);/' node_modules/vectordb/native.js && next build",
57 ...
58 },
59 ...
60}
61```