Hey there! This is a Fork of Ce11an's OpenAI<>SurrealDB demo.
You've just stumbled upon a cool little project that's all about mashing up the brilliance of Gemini with the database wizardry of SurrealDB. Think of this as a sandbox where we're diving deep into the realms of Retrival Augmented Generation (RAG) by mixing up a large dataset of SurrealDB's documentation articles with some fancy vector storage and search capabilities.
We're on a mission to explore the frontiers of what's possible when you pair up SurrealDB with Gemini. We're talking about importing a whopping, umm handful, of SurrealDB documentation articles, complete with their vectors, and then whipping up a RAG question-answering system that's as cool as it sounds.
We've got a cozy little FastAPI server acting as our backstage crew, Jinja2 spinning up the templates, and htmx making our frontend chat application as lively as a chat at your favorite coffee shop.
Before diving in, here's what we're playing with:
- A shiny Apple M2 Pro running MacOS Sonoma 14.4
- SurrealDB 1.3.0, cozied up on disk
- Python 3.11, because we like to keep things fresh
Hit a snag? Just holler, and we'll sort it out together.
First off, make sure SurrealDB is ready to rock on your machine (check out how to get it up and running). For Python 3.11, pyenv is your best buddy.
Grab this repo with:
git clone https://github.com/apireno/surrealdb-gemini.gitYou're gonna need an Gemini API key for this shindig. Not sure where to snag one? TBD
DEFINE FUNCTION IF NOT EXISTS fn::get_gemini_token() {
RETURN "<your-secret-key-here>"
};Heads up: This is all for kicks and not meant for the production grind. Keep your Gemini API key under wraps!
With your setup ready, hit up some make commands to get SurrealDB into gear:
Fire up SurrealDB for some on-disk action:
make surreal-startTo lay down the database blueprint with table and function definitions:
make surreal-initNeed a clean slate? Here's how to clear your database:
make surreal-removeJump into the Python virtual environment:
source venv/bin/activateGet all the project goodies installed:
pip install -e .We're going for the use SurrealDB's documentation git repository to pull some articles and generate vector embeddings (https://github.com/surrealdb/docs.surrealdb.com). Ready to download it?
get-docs-dataTime to move that dataset into SurrealDB:
surreal-docs-insertDive into SurrealDB with SurrealQL:
make surreal-sqlAnd here's a taste of what you can do with a RAG operation:
RETURN fn::surreal_rag("gemini-pro", "What is a RELATE statement about?", 0.4);To start chatting with the RAG:
make server-start
Beyond the RAG adventure, feel free to query, explore, and play with the data in any way you fancy. And if you're looking to amp up your game, tools like LangChain are there to spice things up.
- Handle them darn errors! Reply with a system message that informs the user there has been an oopsie.
- Add user chat history as context.
- There are way too many steps to get started - docker-compose?
- Perform RAG to generate SurrealQL QA - this I will need help with.
- Ummm where are the tests? You, the user, are the test! (seriously, I need to add some...).
If this little project made your day or saved you a coffee break's worth of time, consider fueling Ce11an's caffeine love:
