Skip to content

Commit

Permalink
feat: add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed Apr 20, 2023
1 parent 698dd47 commit 60bfba1
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/.DS_Store
node_modules
build
.svelte-kit
package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:18 AS builder

WORKDIR /app
RUN npm i -g pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install
COPY . .
RUN BUILD_NODE=1 pnpm build
RUN pnpm pkg delete scripts.prepare
RUN pnpm prune --prod

FROM node:18-alpine

WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/build ./build
COPY --from=builder /app/package.json ./package.json

ENTRYPOINT [ "node", "build" ]
64 changes: 62 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# KVec

Use Cloudflare KV or Upstash Redis with OpenAI/Cohere Text Embedding and Pinecone/Qdrant Vector Database.
A modular semantic search stack.

![icon](static/icon.png)
It can be fully cloud-based with **Cloudflare KV** or **Upstash Redis**, **OpenAI** or **Cohere** Text Embedding, and **Pinecone** or **Qdrant Cloud** Vector Database.

It can also be self-hosted with **CouchDB**, **Qdrant** on Docker.

![KVec icon, created with leonardo.ai](static/icon.png)

## Features

Expand Down Expand Up @@ -36,6 +40,61 @@ And bind a KV namespace:
> 2. Create a new Cloudflare Pages project, connect to your forked repo, and setup the environment variables.
> 3. Create a KV namespace and bind it to the project.
### Docker

To use KVec with Docker, you'll need to setup environment variables in the `.env` file.

You may want something like this:

```bash
PORT="8080"
ORIGIN="http://localhost:8080"
APP_SECRET="my-kvec-secret"

# Adapter
HF_API_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Encoder
COHERE_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# VecStore
QDRANT_SERVER="http://qdrant:6333"
QDRANT_COLLECTION="kvec"

# ObjStore
COUCHDB_URL="http://couchdb:5984"
COUCHDB_DB="kvec"
COUCHDB_USER="admin"
COUCHDB_PASSWORD="password"
```

Then, you can run the following command to start:

```bash
docker compose up -d
```

To setup the Qdrant collection at the first time, you can run the following command:

```bash
curl -X 'PUT' 'http://localhost:6333/collections/kvec' -H 'accept: application/json' -H 'content-type: application/json' -d '
{
"vectors": {
"size": 4096,
"distance": "Cosine"
}
}'
# The vector size for Cohere's embedding is 4096, if you are using OpenAI's embedding, you should change it to 1536.
```

To setup the CouchDB database at the first time, you can run the following command:

```bash
curl -X PUT http://admin:password@localhost:5984/kvec
```

Now, you should be able to access the dashboard from `http://localhost:8080/`.

## GUI

You can use the dashboard GUI to manage items and issue tokens.
Expand Down Expand Up @@ -241,6 +300,7 @@ Currently, the following implementations are available:
- **ObjStore**
- [x] `CloudflareKVObjStore`: Use [Cloudflare KV](https://www.cloudflare.com/products/workers-kv/) as the object store backend
- [x] `UpstashRedisObjStore`: Use [Upstash Redis](https://upstash.com/) as the object store backend
- [x] `CouchDBObjStore`: Use [CouchDBObjStore](https://couchdb.apache.org/) as the object store backend
- [x] `MemoryObjStore`: Only for local development
- **VecStore**
- [x] `PineconeVecStore`: Use [Pinecone](https://www.pinecone.io/) as the vector store backend
Expand Down
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
kvec:
image: jacoblincool/kvec
build:
context: .
dockerfile: Dockerfile
ports:
- "${PORT}:${PORT}"
env_file:
- .env
qdrant:
image: qdrant/qdrant
ports:
- "6333:6333"
volumes:
- qdrant:/qdrant/storage
couchdb:
image: couchdb
ports:
- "5984:5984"
volumes:
- couchdb:/opt/couchdb/data
- ./extra/couchdb/local.ini:/opt/couchdb/etc/local.ini
env_file:
- .env

volumes:
qdrant: {}
couchdb: {}
2 changes: 2 additions & 0 deletions extra/couchdb/local.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[couchdb]
single_node=true
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "prettier --ignore-path .gitignore --check **/*.{ts,js,json,yaml,yml,svelte,html,css} && eslint .",
"format": "prettier --ignore-path .gitignore --write **/*.{ts,js,json,yaml,yml,svelte,html,css}",
"changeset": "changeset",
"upload": "pnpm build && wrangler pages publish --project-name kvec .svelte-kit/cloudflare",
"upload": "CF_PAGES=1 pnpm build && wrangler pages publish --project-name kvec .svelte-kit/cloudflare",
"tail": "wrangler pages deployment tail --project-name kvec"
},
"devDependencies": {
Expand All @@ -28,6 +28,7 @@
"@playwright/test": "^1.32.3",
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-cloudflare": "^2.2.0",
"@sveltejs/adapter-node": "^1.2.3",
"@sveltejs/kit": "^1.15.5",
"@tailwindcss/typography": "^0.5.9",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand Down

0 comments on commit 60bfba1

Please sign in to comment.