Files
khoj/src/app
Debanjum 9acc722f7f [Multi-User Part 4]: Authenticate using API Tokens (#513)
###  New
- Use API keys to authenticate from Desktop, Obsidian, Emacs clients
- Create API, UI on web app config page to CRUD API Keys
- Create user API keys table and functions to CRUD them in Database

### 🧪 Improve
- Default to better search model, [gte-small](https://huggingface.co/thenlper/gte-small), to improve search quality
- Only load chat model to GPU if enough space, throw error on load failure
- Show encoding progress, truncate headings to max chars supported
- Add instruction to create db in Django DB setup Readme

### ⚙️ Fix
- Fix error handling when configure offline chat via Web UI
- Do not warn in anon mode about Google OAuth env vars not being set
- Fix path to load static files when server started from project root
2023-10-26 12:33:03 -07:00
..

Django App

Khoj uses Django as the backend framework primarily for its powerful ORM and the admin interface. The Django app is located in the src/app directory. We have one installed app, under the /database/ directory. This app is responsible for all the database related operations and holds all of our models. You can find the extensive Django documentation here 🌈.

Setup (Docker)

Prerequisites

  1. Ensure you have Docker installed.
  2. Ensure you have Docker Compose installed.

Run

Using the docker-compose.yml file in the root directory, you can run the Khoj app using the following command:

docker-compose up

Setup (Local)

Install dependencies

pip install -e '.[dev]'

Setup the database

  1. Ensure you have Postgres installed. For MacOS, you can use Postgres.app.
  2. If you're not using Postgres.app, you may have to install the pgvector extension manually. You can find the instructions here. If you're using Postgres.app, you can skip this step. Reproduced instructions below for convenience.
cd /tmp
git clone --branch v0.5.1 https://github.com/pgvector/pgvector.git
cd pgvector
make
make install # may need sudo
  1. Create a database

Create the khoj database

createdb khoj -U postgres

Make migrations

This command will create the migrations for the database app. This command should be run whenever a new model is added to the database app or an existing model is modified (updated or deleted).

python3 src/manage.py makemigrations

Run migrations

This command will run any pending migrations in your application.

python3 src/manage.py migrate

Run the server

While we're using Django for the ORM, we're still using the FastAPI server for the API. This command automatically scaffolds the Django application in the backend.

python3 src/khoj/main.py