https://github.com/neondatabase-labs/ask-neon
Chatbot: Search your own knowledge base by semantic similarity
https://github.com/neondatabase-labs/ask-neon
ai chatbot embeddings openai postgres postgresql
Last synced: 9 months ago
JSON representation
Chatbot: Search your own knowledge base by semantic similarity
- Host: GitHub
- URL: https://github.com/neondatabase-labs/ask-neon
- Owner: neondatabase-labs
- Created: 2023-03-01T16:56:25.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-09T16:32:17.000Z (over 2 years ago)
- Last Synced: 2025-03-23T09:24:10.899Z (over 1 year ago)
- Topics: ai, chatbot, embeddings, openai, postgres, postgresql
- Language: TypeScript
- Homepage: https://neon.tech/ai
- Size: 2.78 MB
- Stars: 59
- Watchers: 8
- Forks: 7
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Postgres Q&A

Postgres Q&A is a project that demonstrates how to use word embeddings and Postgres to build a chatbot. The chatbot is implemented using Vercel Edge Functions and the @neondatabase/serverless driver, and relies on OpenAI's GPT-3 API to generate responses.
## Getting started
To get started with this project, you'll need to have:
- A Neon account, and project.
- an API key for the OpenAI GPT API, which you can obtain from https://openai.com/.
Once you have the prerequisites installed, follow these steps to get the project up and running:
Clone the repository:
```bash
git clone https://github.com/neondatabase/postgres-qa.git
cd ask-postgres
```
## Prepare the data
### Import embeddings to Neon
This section is derived from OpenAI’s cookbook example. You can use the Python code here to build a web crawler and extract the text you need to create embeddings. We’ve already created the text files based on https://www.postgresql.org/docs/, which you can find in `data/text` directory.
To get started, move to the `data` directory create a new environment and install the dependencies:
```bash
cd data
python -m venv env
source env/bin/activate
pip install -r requirements.txt
```
Import the schema to your database:
```bash
psql -f database.sql
```
Let’s now add `DATABASE_URL` and `OPENAI_API_KEY` to our environment variables:
```bash
export DATABASE_URL= OPENAI_API_KEY=
```
Run `main.py` to import the emebbeding to your Neon database:
```bash
python main.py
```
Relax and grab a cup of coffee as this section might take 10min to process!
Expcted result:
```bash
Saving to CSV...
Loading tokenizer...
Embedding text...
Connecting to database...
Done!
```
Install the project dependencies:
```bash
cd app
npm install
```
Create a .env file
```bash
touch .env.local
```
Set the following environment variables:
```
OPENAI_API_KEY= Your OpenAI API key.
DATABASE_URL= The connection URL for your Neon database.
```
Start the server:
```bash
npm run dev
```
## Contributing
We welcome contributions to this project! If you find a bug, have a suggestion, or want to contribute code, please open an issue or pull request on the GitHub repository.
## License
This project is licensed under the MIT License. See the LICENSE file for more information.