Skip to content

Commit

Permalink
added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhravya committed Apr 15, 2024
1 parent 96e5861 commit 205575c
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 52 deletions.
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
![og image](https://supermemory.dhr.wtf/og-image.png)

# SuperMemory

## 👀 What is this?

Build your own second brain with supermemory. It's a ChatGPT for your bookmarks. Import tweets or save websites and content using the [chrome extension](https://chromewebstore.google.com/detail/supermemory/afpgkkipfdpeaflnpoaffkcankadgjfc?hl=en-GB&authuser=0) (the extension on webstore is not updated, please use the one in the repo)

Well, here's the thing - me and @yxshv save a _lot_ of content on the internet.

Twitter bookmarks, websites, snippets, etc.

But we never look back to it - to us, it's like throwing information in the void.

Supermemory fixes this.

## How do I use this?

Just go to [supermemory.dhr.wtf](https://supermemory.dhr.wtf) and sign in with your google account.

To use the chrome extension, please download it from the [releases page](https://github.com/dhravya/supermemory/releases) and load it in chrome.

## 👨‍💻 The Stack

![overview](https://i.dhr.wtf/r/Clipboard_Apr_14,_2024_at_4.52 PM.png)

Supermemory has three main modules, managed by [turborepo](https://turbo.build):

#### `apps/web`: The main web UI.

The database, auth etc logic is here

![App preview](https://i.dhr.wtf/r/Clipboard_Apr_14,_2024_at_4.10 PM.png)

Built with:

- Nextjs 14
- [Next Auth](https://next-auth.js.org/)
- [Drizzle ORM](https://drizzle.team/)
- [Cloudflare D1 database](https://developers.cloudflare.com/d1/get-started/)
- Cloudflare ratelimiter
- [TailwindCSS](https://tailwindcss.com)
- [shadcn-ui](https://ui.shadcn.com)
- And some other amazing open source projects like [Novel](https://novel.sh) and [vaul](https://vaul.emilkowal.ski/)
- Hosted on Cloudflare Pages

#### `apps/extension`: Chrome extension

The chrome extension is one of the most important part of the setup, but is not required.This is to easily add pages to your memory.

![Chrome extension preview](https://i.dhr.wtf/r/Clipboard_Apr_14,_2024_at_3.54 PM.png)

You can also use it to import all your twitter bookmarks!
![Import bookmarks](https://i.dhr.wtf/r/Clipboard_Apr_14,_2024_at_3.56 PM.png)

Built with:

- [CRXJS](https://crxjs.dev/vite-plugin/getting-started/react/create-project)
- Vite
- [TailwindCSS](https://tailwindcss.com)
- [shadcn-ui](https://ui.shadcn.com)
- React

#### `apps/cf-ai-backend`: This module handles the vector store and AI response generation

This is where the magic happens!
Built with:

- Cloudflare Workers
- [Cloudflare AI](https://ai.cloudflare.com)
- [Cloudflare Vectorize](https://developers.cloudflare.com/vectorize/)
- [Cloudflare Queues](https://developers.cloudflare.com/queues/)
- [Cloudflare Browser Rendering](https://developers.cloudflare.com/browser-rendering/)
- [Cloudflare KV](https://developers.cloudflare.com/kv)

## Contribute or self host

Supermemory is design to be set up easily locally and super duper easy to set up 💫

Please see the [SETUP-GUIDE.md](SETUP-GUIDE.md) for setup instructions.

### Contributing

Contributions are very welcome! A contribution can be as small as a ⭐ or even finding and creating issues.
77 changes: 77 additions & 0 deletions SETUP-GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Setup guide

## Prerequisites

- [bun](https://bun.sh/)
- [wrangler](https://developers.cloudflare.com/workers/cli-wrangler/install-update)

## Steps

1. Clone the repo
2. Run `bun install` in the root directory
3. Create a `.dev.vars` file in `apps/web` with the following content:

```bash
GOOGLE_CLIENT_ID="-"
GOOGLE_CLIENT_SECRET="-"
NEXTAUTH_SECRET='nextauthsecret'
DATABASE_URL='database.sqlite'
NEXTAUTH_URL='http://localhost:3000'
BACKEND_SECURITY_KEY='veryrandomsecuritykey'
```

4. Setup the database:

First, edit the `wrangler.toml` file in `apps/web` to point the d1 database to your account.

You can create a d1 database by running this command

```
wrangler d1 create DATABASE_NAME
```

And then replace these values

```
[[d1_databases]]
binding = "DATABASE"
database_name = "YOUR_DATABASE_NAME"
database_id = "YOUR_DB_ID"
```

Simply run this command in `apps/web`

```
wrangler d1 execute dev-d1-anycontext --local --file=db/prepare.sql
```

If it runs, you can set up the cloud database as well by removing the `--local` flag.

5. You need to host your own worker for the `apps/cf-ai-backend` module.

To do this, first edit the `.dev.vars` file in `apps/cf-ai-backend` with the following content:

```bash
SECURITY_KEY ="veryrandomsecuritykey"
// Why? to generate embeddings with 4000+ tokens
OPENAI_API_KEY="sk-"
```

6. Run this command to initialise vector database

```
wrangler vectorize create --dimensions=1536 supermem-vector-1 --metric=cosine
```

7. Change the `wrangler.toml` file in `apps/cf-ai-backend` to point to your KV namespace

8. Run `bun dev` in the root directory and Voila! You have your own supermemory instance running!

> Note: You need to replace the url `https://cf-ai-backend.dhr.wtf` everywhere with your own url for the cf-ai-backend module.
## Deploying

To deploy the web app, run `bun deploy` in the `apps/web` directory.
To deploy the cf-ai-backend module, run `wrangler publish` in the `apps/cf-ai-backend` directory.

To get the extension running, you need to build it first. Run `bun build` in the `apps/extension` directory and then load the extension in chrome.
48 changes: 0 additions & 48 deletions apps/cf-ai-backend/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,3 @@ binding = "MYBROWSER"

[placement]
mode = "smart"

# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
# Note: Use secrets to store sensitive data.
# Docs: https://developers.cloudflare.com/workers/platform/environment-variables
# [vars]
# MY_VARIABLE = "production_value"

# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
# Docs: https://developers.cloudflare.com/workers/runtime-apis/kv
# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
# Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"

# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
# Docs: https://developers.cloudflare.com/queues/get-started
# [[queues.producers]]
# binding = "MY_QUEUE"
# queue = "my-queue"

# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
# Docs: https://developers.cloudflare.com/queues/get-started
# [[queues.consumers]]
# queue = "my-queue"

# Bind another Worker service. Use this binding to call another Worker without network overhead.
# Docs: https://developers.cloudflare.com/workers/platform/services
# [[services]]
# binding = "MY_SERVICE"
# service = "my-service"

# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
# [[durable_objects.bindings]]
# name = "MY_DURABLE_OBJECT"
# class_name = "MyDurableObject"

# Durable Object migrations.
# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
# [[migrations]]
# tag = "v1"
# new_classes = ["MyDurableObject"]
4 changes: 0 additions & 4 deletions apps/web/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ name = "web"
compatibility_date = "2024-03-29"
compatibility_flags = ["nodejs_compat"]

[[vectorize]]
binding = "VECTORIZE_INDEX"
index_name = "anycontext-idx"

[[d1_databases]]
binding = "DATABASE"
database_name = "dev-d1-anycontext"
Expand Down

0 comments on commit 205575c

Please sign in to comment.