Using LangChainJS and Cloudflare Workers together
blog.cloudflare.com
blog.cloudflare.com
Cloudflare is great and I love working with them, but Wrangler and way that there have been multiple major shifts in the way that Workers are set up over the years has become a bit frustrating at times.
Same error when tried in deno but with more details:
TypeError: Cannot read properties of undefined (reading 'replaceAll')
at R.embedQuery (https://esm.sh/v122/langchain@0.0.77/deno/embeddings/openai.js:4:319)
at u.similaritySearch (https://esm.sh/v122/langchain@0.0.77/deno/vectorstores/memory.js:2:896)Edit:
Ok. I haven't been able to reproduce this issue (I know "it worked on my machine" is the worst answer. But I did do a fresh setup on two other machines to see if I can recreate so it worked on three of my machines?).
If you want to drop me an email (my email is in my profile), I'm happy to help find time to debug live and I'd personally love to find out what the issue is. And/or hook you up with a t-shirt :)
Digging in, this specific error looks like it is happening when LangChain is trying to strip out new lines (you can see the code in LangChain here: https://github.com/hwchase17/langchainjs/blob/main/langchain...). For some reason your documents or embeddings are undefined. But I've been unable to create a scenario where that happens.
I wondered if perhaps your OpenAI API Key wasn't set correctly and it was causing the Embeddings to fail, but I tried both deleting my key and setting to bogus key and the error was different.
Any chance you switched out the URL we were pulling from? That didn't cause the same error for me either, but thinking through what else it could be.
Sorry to not resolve, but please feel free to drop me an email. I'll keep trying to reproduce as well, and will jump back in this comment if I do (and find a fix).
I personally feel like with a lot of these emerging AI tools I still find myself still in the exploration phase. Trying to understand how they work and what they do, to then wrap my ahead around why I use them. Some of this post is a look into how I've been wrapping my head around the what and how of LangChain. Doing a follow-up digging deeper into the "why" and what benefits folks may see from this kind of setup is a really good nudge for me. Thanks!
If you have any specific questions, or want to chat with someone else using it, please don't be shy. My email and twitter handle are both in my profile. I truly love talking about all of this and hearing what other folks are working on.
(plan to talk about how we built it soon)
edit: clarify i work at cloudflare
Neat! Reminds me of using DynamoDB as a multi-dimensional store with (space-filling curve) z-order indexing [0], which isn't as fast (as native spatial databases, say) but it works. I wonder how performant retrofitting Workers KV is compared to a native vector database? Please do publish benchmarks, if possible.
[0] https://archive.is/ZGY1T / https://news.ycombinator.com/item?id=30009893