๐Ÿ“ฆ elithrar / pinecone-workers-demo

Use Cloudflare Workers (https://workers.dev) to query a Pinecone vector database (https://www.pinecone.io/)

โ˜… 6 stars โ‘‚ 0 forks ๐Ÿ‘ 6 watching โš–๏ธ BSD 3-Clause "New" or "Revised" License
๐Ÿ“ฅ Clone https://github.com/elithrar/pinecone-workers-demo.git
HTTPS git clone https://github.com/elithrar/pinecone-workers-demo.git
SSH git clone git@github.com:elithrar/pinecone-workers-demo.git
CLI gh repo clone elithrar/pinecone-workers-demo
Loading files...
๐Ÿ“„ README.md

Demo: Cloudflare Workers + Pinecone (a vector database)

Note: ๐Ÿงช This is a example application and is not officially supported by Cloudflare.

Query (and create!) vectors in Pinecone from Cloudflare Workers.

Deploying the Demo

  • Clone this repository: git clone https://github.com/elithrar/pinecone-workers-demo.git
  • Change into the directory (cd pinecone-workers-demo) and install the dependencies: npm install
  • Get a Pinecone API key
  • Set that key as a wrangler secret: wrangler secret put PINECONE_API_KEY (follow the prompts)
  • Deploy the demo app to your Cloudflare account: wrangler deploy and note the URL returned - e.g. https://pinecone-demo.YOUR_SUBDOMAIN.workers.dev
The demo app exposes a few endpoints:

# Create the initial index (this can take a few minutes to be ready on Pinecone's side)
curl -X POST "https://pinecone-demo.YOUR_SUBDOMAIN.workers.dev/indexes/example-index"

# Check on its status
curl "https://pinecone-demo.YOUR_SUBDOMAIN.workers.dev/indexes/example-index"

# Insert a couple of example vectors
curl -X POST "https://pinecone-demo.YOUR_SUBDOMAIN.workers.dev/indexes/example-index/upsert"

# Query them!
curl "https://pinecone-demo.YOUR_SUBDOMAIN.workers.dev/indexes/example-index/query"

If you want to learn more, visit Pinecone's documentation.

Where to from here?

This is only a basic example of how to wire up Pinecone + Workers, but you could:

  • Use the Cache API to cache common queries and return them from cache (vs. querying your Pinecone index each time)
  • Tie in authentication using Hono's middleware: https://hono.dev/middleware/builtin/bearer-auth
  • Handle errors more politely when an index is still being created (!)
  • Accept dynamic queries via the /query endpoint vs. just a static query

Built with

Built with Cloudflare Workers, the Hono API framework, and deployed to Cloudflare's global network.

License

Copyright Cloudflare, Inc (2023). BSD-3-Clause licensed. See the LICENSE file for details.