This integration is only supported in Cloudflare Workers.
For longer-term persistence across chat sessions, you can swap out the default in-memory chatHistory that backs chat memory classes like BufferMemory for a Cloudflare D1 instance.
You’ll need to install the LangChain Cloudflare integration package.
For the below example, we also use Anthropic, but you can use any model you’d like:
Set up a D1 instance for your worker by following the official documentation. Your project’s wrangler.toml file should
look something like this:
Copy
Ask AI
name = "YOUR_PROJECT_NAME"main = "src/index.ts"compatibility_date = "2024-01-10"[vars]ANTHROPIC_API_KEY = "YOUR_ANTHROPIC_KEY"[[d1_databases]]binding = "DB" # available in your Worker as env.DBdatabase_name = "YOUR_D1_DB_NAME"database_id = "YOUR_D1_DB_ID"