Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supabase Self-Host Implementation #8

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fd927ea
Feat: Modify docker-compose.yaml and enviroments to work with supabas…
thihanmoekyaw Nov 6, 2024
ffa3f53
Added Supabase as a submodule
thihanmoekyaw Nov 11, 2024
7b29e08
feat: add healthcheck and init script for Docker services
thihanmoekyaw Nov 11, 2024
52b202d
feat: add supabase integration
thihanmoekyaw Nov 12, 2024
f6a4711
remove supabase components in .gitignore:
thihanmoekyaw Nov 12, 2024
005be3a
add condition to produce a .env file for supabase if there is none
thihanmoekyaw Nov 14, 2024
0844727
Add another if else statement to init.sh to make sure user run the co…
thihanmoekyaw Nov 14, 2024
ca05495
Add QDRANT_API_KEY to .env and to docker compose
KastanDay Nov 14, 2024
66b3d42
Make supabase a SPARSE submodule, faster clone and maximally simple f…
KastanDay Nov 15, 2024
226393c
Sparse checkout of supabase module in init
KastanDay Nov 15, 2024
49e15d0
remove envrionment variables in docker-compose.yaml flask container
thihanmoekyaw Nov 18, 2024
53fcdc4
minor line space removing
thihanmoekyaw Nov 18, 2024
7f1aa92
Fix qdrant requiring API key
thihanmoekyaw Nov 18, 2024
adbdab6
Debugging issues with MinIO
thihanmoekyaw Nov 18, 2024
ae2c2ae
fix issue with nomic in self hosting
thihanmoekyaw Nov 19, 2024
1ca1a6a
Merge Asmita's ingest queue results into here
KastanDay Nov 20, 2024
3a58849
Merge branch 'main' into supabase-implementation
KastanDay Nov 20, 2024
7e06008
Fix: fix probelms with the flask and redis docker images to capturing…
thihanmoekyaw Nov 25, 2024
4203eae
Added UIUC-Chatbot/crawlee as a submodule
thihanmoekyaw Dec 16, 2024
14dfbb5
Add crawlee to docker
thihanmoekyaw Dec 16, 2024
da7526a
change port values for crawlee
thihanmoekyaw Dec 16, 2024
ecb7175
Clarify what flask port clawlee have to listen
thihanmoekyaw Dec 17, 2024
8b84593
Fix read/write issue of Docker on vForge
thihanmoekyaw Jan 7, 2025
8f0eea7
Working ingest queue and so so much more. it's a delight
KastanDay Jan 10, 2025
7f1b579
Improve qdrant API key handling
KastanDay Jan 10, 2025
24fa359
Add Minio and Qdrant initialization. Make init script not delete your…
KastanDay Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 32 additions & 42 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
# ALL SERVICES ARE CONFIGURED HERE.
# You can use these defaults, or BYO services to fit your needs.
# The defaults should work 'out of the box' without any changes.
# ⚠️ For Security, we recommend changing all variables marked with CHANGE ME.
# OpenAI API key, required and please add one
OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE

# OpenAI key is REQUIRED for Embeddings during ingest & RAG retrieval
OPENAI_API_KEY= # ⚠️ CHANGE ME
# Main backend Flask app
FLASK_PORT=3012

# Qdrant Vector DB
QDRANT_URL=qdrant:6333 # container name
QDRANT_COLLECTION_NAME=uiuc-chat
QDRANT_API_KEY=your-strong-key-here # ⚠️ CHANGE ME
# Ingest queue state is managed by Redis
INGEST_REDIS_HOST=redis # container name
INGEST_REDIS_PASSWORD=your-strong-password-here # ⚠️ CHANGE ME
INGEST_REDIS_PORT=6379

# Object Storage: You can use either Minio or S3. Choose one, not both. Minio is used by default.
MINIO_URL=http://minio:9001 # You MUST comment this out if using AWS S3.
AWS_ACCESS_KEY_ID=minioadmin # ⚠️ CHANGE ME
AWS_SECRET_ACCESS_KEY=minioadmin # ⚠️ CHANGE ME
S3_BUCKET_NAME=uiuc-chat

# For SQL, you have 3 options: Supabase, Postgres, or SQLite. Choose only one.
# Self-hosted Supabase is used by default, see here for more info on self hosted Supabase: https://supabase.com/docs/guides/self-hosting

# DEFAULT SQL: Supabase
# TODO: FIGURE OUT THE DEFAULTS HERE
# SUPABASE_USER=
# SUPABASE_PASSWORD=
# SUPABASE_URL=
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
DOCKER_INTERNAL_MINIO_API_PORT=10000
DOCKER_INTERNAL_MINIO_DASHBOARD_PORT=10001
PUBLIC_MINIO_API_PORT=3013
PUBLIC_MINIO_DASHBOARD_PORT=3014
MINIO_URL=http://minio:${DOCKER_INTERNAL_MINIO_API_PORT}

# Or, bring your own Postgres (from outside this repo):
# POSTGRES_USER=
# POSTGRES_PASSWORD=
# POSTGRES_URL=
# Qdrant Vector DB
# QDRANT_API_KEY is set in the qdrant_config.yaml
QDRANT_COLLECTION_NAME=uiuc-chat
QDRANT_URL=http://qdrant:6333
S3_BUCKET_NAME=uiuc-chat

# Or, use SQLite. I'm a huge fan of SQLite:
# SQLITE_DB_NAME=uiuc-chat-backend-sqlite.db
# Supabase related, should match the values in the Supabase .env file
POSTGRES_PASSWORD=your-super-secret-and-long-postgres-password # Must match Supabase's password
POSTGRES_HOST=supabase-db
POSTGRES_PORT=5432
POSTGRES_DB=postgres
POSTGRES_USER=postgres

# Ingest queue state is managed by Redis
INGEST_REDIS_HOST=redis # container name
INGEST_REDIS_PORT=6379
INGEST_REDIS_PASSWORD=your-strong-password-here # ⚠️ CHANGE ME

# Main backend Flask app
FLASK_PORT=8000
# Application variables
S3_BUCKET_NAME=uiuc-chat
OPENAI_API_KEY=YOUR_KEY_HERE # replace with your OpenAI API key

# Optional services. Adds functionality if you want it, but not necessary.
# NOMIC_API_KEY=
# POSTHOG_API_KEY=
# SENTRY_DSN=
# EMAIL_SENDER=
# N8N_URL=
# Optional
# POSTHOG_API_KEY=OPTIONAL
# NOMIC_API_KEY=OPTIONAL
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "supabase"]
path = supabase
url = https://github.com/supabase/supabase
[submodule "ic_crawlee"]
path = ic_crawlee
url = https://github.com/UIUC-Chatbot/crawlee.git
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@ Failure to obtain a commercial license for commercial use is a violation of the

## Docker Deployment

### Supabase

1. Duplicate `.env.example` from `supabase/docker/.env.example` and rename it to `.env`. (example: cp ./supabase/docker/.env.example ./supabase/docker/.env)
2. Customize your env variables as needed in the supabase docker

### Self-host docker

1. Duplicate `.env.template` and rename it to `.env`. E.g. `cp .env.template .env`
2. Customize your env variables. Your vector database can be either Qdrant and Pinecone. The SQL database can be any of SQLite, Postgres, and Supabase. The object storage can be Minio or AWS S3.
3. Run Docker Compose `docker compose up --build`
4. Navitage to `localhost:8000` (or whatever your `$FLASK_PORT` is)

To customize HTTP port used as the main entrypoint, set the `FLASK_PORT` variabel in your `.env`. It defaults to 8000.
### Running simultaneously

We've created an `init.sh` file to run both docker-compose files with run command. To do this, first initialize the `init.sh` with right permission.

```bash
chmod +x init.sh
./init.sh #runs the script
```

To customize HTTP port used as the main entrypoint, set the `FLASK_PORT` variabel in your `.env`. It defaults to 8188.

Works on version: `Docker Compose version v2.27.1-desktop.1`

Expand All @@ -43,7 +57,7 @@ See docs on https://docs.uiuc.chat

1. Rename `.env.template` to `.env` and fill in the required variables
2. Install Python requirements `pip install -r requirements.txt`
3. Start the server for development (with live reloads) `cd ai_ta_backend` then `flask --app ai_ta_backend.main:app --debug run --port 8000`
3. Start the server for development (with live reloads) `cd ai_ta_backend` then `flask --app ai_ta_backend.main:app --debug run --port 8188`

The docs are auto-built and deployed to [our docs website](https://uiuc-chatbot.github.io/ai-ta-backend/) on every push. Or you can build the docs locally when writing:

Expand All @@ -61,3 +75,8 @@ The docs are auto-built and deployed to [our docs website](https://uiuc-chatbot.
'url': doc.metadata.get('url'), # wouldn't this error out?
'base_url': doc.metadata.get('base_url'),
```


### Note

For Supabase, the current version we are using is v1.24.09 ([link](https://github.com/supabase/supabase/tree/v1.24.09))
6 changes: 3 additions & 3 deletions ai_ta_backend/database/qdrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def __init__(self):
"""
# vector DB
self.qdrant_client = QdrantClient(
url='http://qdrant:6333',
url=os.getenv('QDRANT_URL', 'http://qdrant:6333'), # Default to localhost if not set
https=False,
api_key=os.environ['QDRANT_API_KEY'],
timeout=20, # default is 5 seconds. Getting timeout errors w/ document groups.
api_key=os.getenv('QDRANT_API_KEY'),
timeout=20,
)

self.vectorstore = Qdrant(
Expand Down
Loading