With Cloudflare Worker
In this guide, you'll learn how to use LlamaIndex with CloudFlare Worker
Before you start, make sure you have try LlamaIndex.TS in Node.js to make sure you understand the basics.
Getting Started with LlamaIndex.TS in Node.js
Also, you need have the basic understanding of Cloudflare Worker.
Adding environment variables
Then, you need create .dev.vars
and add LLM api keys for the local development, such as OPENAI_API_KEY
for OpenAI API key.
Do not commit the api key to git repository.
Integrating with Hono
Difference between Node.js and Cloudflare Worker
In Cloudflare Worker and similar serverless JS environment, you need to be aware of the following differences:
- Some Node.js modules are not available in Cloudflare Worker, such as
node:fs
,node:child_process
,node:cluster
... - You are recommend to design your code using network request, such as use
fetch
API to communicate with database, insteadof a long-running process in Node.js. - Some of LlamaIndex.TS packages are not available in Cloudflare Worker, for example
@llamaindex/readers
and@llamaindex/huggingface
. - The main
llamaindex
is designed to work in all JavaScript environment, including Cloudflare Worker. If you find any issue, please report to us. @llamaindex/env
is a JS environment binding module, which polyfill some Node.js/Modern Web API (for example, we have a memory basedfs
module, and Crypto API polyfill). It is designed to work in all JavaScript environment, including Cloudflare Worker.
Edit on GitHub
Last updated on