AthenaDB is a simple, serverless, distributed vector database that can be used as an API. It is written with Cloudflare Workers AI, D1, Vectorize.
wrangler login. AthenaDB requires a $5/month Workers subscription to function.git clone https://github.com/TimeSurgeLabs/athenadb.git
cd athenadb
npm run create-vector
npm run create-dbCopy the output Database ID and paste it in wrangler.toml under database_id . Then, run the following two commands:
npm run init-db
npm run deployYou should get an output with your API URL. You can now use the API endpoints.
POST /:namespace/insertInserts text data into the database. Text is converted into embeddings using Cloudflare AI and stored along with a unique identifier.
input: A single string (max 1024 characters).inputs: An array of strings (each max 1024 characters).POST /:namespace/queryQueries the database for similar text embeddings. Specify ?limit=number in the URL to specify the number of results to return. The default is 5, the maximum is 20.
input: A single string for querying. (max 1024 characters)inputs: An array of strings for batch querying. (each max 1024 characters)GET /:namespace/:uuidRetrieves a specific entry from the database using its unique identifier (UUID). Add query parameters ?vector=true to retrieve the vector along with the entry. Add query parameters ?db_id=true to retrieve the SQL table ID along with the entry.
GET /:namespace?limit=10&offset=0Retrieves all entries from the given namespace. Limit can be set to a maximum of 100 entries. Add query parameters ?vector=true to retrieve the vectors along with the entries. Add query parameters ?db_id=true to retrieve the SQL table ID along with the entries.
DELETE /:namespace/:uuidDeletes a specific entry from the database using its unique identifier (UUID). Warning: This action is irreversible.
DELETE /:namespaceDeletes all entries from the given namespace. Warning: This action is irreversible.
POST /embeddingsGenerates embeddings for given text without storing it in the database.
text: A string whose embedding is to be generated.GET /A test endpoint that returns 'Hello world!' as a response.
fetch('https://athenadb.yourusername.workers.dev/your-namespace/insert', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ input: 'Your text here' })
})fetch('https://athenadb.yourusername.workers.dev/your-namespace/query', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ input: 'Query text' })
})fetch('https://athenadb.yourusername.workers.dev/your-namespace/your-uuid', {
method: 'GET'
})fetch('https://athenadb.yourusername.workers.dev/your-namespace/your-uuid', {
method: 'DELETE'
})fetch('https://athenadb.yourusername.workers.dev/embeddings', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: 'Your text here' })
})