Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Ce11an/surrealdb-openai

Example of RAG using SurrealDB and OpenAI
https://github.com/Ce11an/surrealdb-openai

fastapi htmx jinja2 openai python surrealdb

Last synced: about 1 month ago
JSON representation

Example of RAG using SurrealDB and OpenAI

Awesome Lists containing this project

README

        

# SurrealDB x OpenAI: A Chat Playground

Welcome to a project that explores the synergy between SurrealDB and OpenAI.

https://github.com/Ce11an/surrealdb-openai/assets/60790416/a4e6a967-321a-4ca0-8f64-1687512aab38

## Project Overview

This project aims to demonstrate the potential of integrating SurrealDB with OpenAI by importing 25,000 Wikipedia articles, complete with vector embeddings generated by OpenAI. The ultimate goal is to develop a Retrieval-Augmented Generation (RAG) question-answering system.

The backend is powered by a FastAPI server, with Jinja2 handling template rendering and htmx enriching the frontend chat interface.

## Getting Started

### Prerequisites

1. **SurrealDB**: Ensure that SurrealDB is installed and configured on your machine. Installation instructions are available [here](https://surrealdb.com/install).

2. **Python 3.11**: We use [uv](https://docs.astral.sh/uv/) to manage dependencies.

3. **SurrealDB Python SDK**: The [SurrealDB Python SDK](https://github.com/surrealdb/surrealdb.py/tree/main) is currently in beta. To install the dependency, please ensure you have `rust` installed on your system.

### Installation

1. Clone the repository.

2. You will need an OpenAI API token for this project. If you don't have one, you can obtain it by following the [OpenAI Developer Quickstart](https://platform.openai.com/docs/quickstart). Rename the `.env.example` file to `.env` and replace the placeholder with your key.

**Note:** This project is intended for experimental purposes only. Ensure that your OpenAI API key is kept secure.

### Setting Up SurrealDB

To initialise SurrealDB, use the following `make` commands:

1. Start SurrealDB with on-disk persistence:

```bash
make surreal-start
```

2. Initialise the database with the required tables and functions:

```bash
make surreal-init
```

3. If you need to reset the database:

```bash
make surreal-remove
```

### Python Environment

With `uv` installed, run:

```bash
uv sync
```

Activate the Python virtual environment:

```bash
source .venv/bin/activate
```

### Downloading the Dataset

Download the Simple English Wikipedia dataset, which includes vector embeddings (~700MB compressed, ~1.7GB CSV):

```bash
download-data
```

### Populating SurrealDB

Insert the dataset into SurrealDB:

```bash
surreal-insert
```

### Starting the Chat Application

To start the chat server:

```bash
make server-start
```

## Support

If you find this project helpful, consider supporting the development:

Buy Me A Coffee