A Telegram RAG bot without vector databases: an example on Cloudflare Workers

How do you build a Telegram bot that searches a knowledge base without vector databases or expensive infrastructure? A developer has walked through a working stack: TypeScript and Telegraf for Telegram, the Jaccard algorithm for keyword search, the free Groq API for generating answers, and Cloudflare KV for storing conversation history. The bot deploys in one step to Cloudflare Workers and costs practically nothing to run.

AI-processed from Habr AI; edited by Hamidun News
A Telegram RAG bot without vector databases: an example on Cloudflare Workers
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1TypeScript — the language the whole codebase is written in, with type support
Key metric #2Telegraf — a lightweight and popular library for working with the Telegram API
Key metric #3Cloudflare Workers — a serverless platform for deployment (free plan with generous limits)

A Telegram bot that searches a knowledge base is a popular task. Usually it means a vector database such as Pinecone or Weaviate, embeddings and paid cloud infrastructure. A developer from Habr has shown that this is not required: there is a cheaper and simpler way.

Why vector databases are not the only option

RAG (Retrieval-Augmented Generation) does not strictly require vector embeddings. For a mid-sized knowledge base, full-text keyword search is enough. The Jaccard algorithm measures the similarity of two texts through the overlap of their words. It is simple and fast, and needs no machine learning.

Here is how it works in practice: if the knowledge base contains a tech-support FAQ and a user writes "how to restart the device", the bot splits the query into words, looks for matches in the documents, takes those with the largest overlap and passes them to the LLM. The results can even be better than with expensive embedding APIs, provided the content is well structured. It is also faster, because there is no waiting for embeddings to be generated.

The main benefit: zero dependence on external services other than a single LLM API for generating answers. The conversation history and the knowledge base itself are stored directly in Cloudflare KV, a built-in storage included in the free plan. There is no queue for provisioning infrastructure and no monthly bills for vector storage.

How the architecture works

The flow goes like this: the user writes a question in Telegram → the bot finds relevant documents in the knowledge base with the Jaccard algorithm → it takes the top 3 results and sends them with the question to the Groq API (a free LLM) → Groq generates an answer based on the retrieved documents → the bot sends the result to the chat.

The conversation history is saved in KV to provide context between messages. This lets the bot remember earlier questions and refine its answers depending on the context of the conversation.

Notably, Groq was not chosen at random. It is a fast LLM service with generous free-plan limits, well suited to bots and RAG systems that need an instant response.

The knowledge base itself is stored in KV as a set of documents: the key is the document ID, the value is the text. On each query the bot loads all the documents, applies Jaccard to each and ranks them by similarity score. This approach scales to thousands of documents without problems.

What stack you need

The implementation needs a minimal set of components:

  • TypeScript — the language the whole codebase is written in, with type support
  • Telegraf — a lightweight and popular library for working with the Telegram API
  • Cloudflare Workers — a serverless platform for deployment (free plan with generous limits)
  • Cloudflare KV — built-in storage for the knowledge base and conversation history
  • Groq API — a free LLM service for generating answers from the retrieved documents

Deployment takes a single command through Wrangler, the CLI tool for Cloudflare Workers. There is no server setup, no need for your own hosting, and no Docker containers.

If the bot stays within the Workers free plan (one million requests per month), the cost is exactly zero. For comparison, a typical setup with a vector database costs at least $20-50 per month for storage alone.

What this means for developers

This opens the door to simple RAG systems that used to look too expensive or too complex to build. For small teams, startups and enthusiasts, it is a way to launch an AI bot with knowledge search quickly and practically for free.

A classic example is an internal office bot that answers questions about the FAQ, corporate policies, technical guides and documentation. Such a project used to require an infrastructure budget and the upkeep of a complex system. Now it can all live in a single KV bucket and be up and running in an hour.

This is especially useful for teams that want to add an AI feature quickly without large investment.

Key Questions Answered

Why vector databases are not the only option?

RAG (Retrieval-Augmented Generation) does not strictly require vector embeddings. For a mid-sized knowledge base, full-text keyword search is enough. The Jaccard algorithm measures the similarity of two texts through the overlap of their words. It is simple and fast, and needs no machine learning. Here is how it works in practice: if the knowledge base contains a tech-support FAQ and a user writes "how to restart the device", the bot splits the query into words, looks for matches in the documents, takes those with the largest overlap and passes them to the LLM. The results

How the architecture works?

The flow goes like this: the user writes a question in Telegram → the bot finds relevant documents in the knowledge base with the Jaccard algorithm → it takes the top 3 results and sends them with the question to the Groq API (a free LLM) → Groq generates an answer based on the retrieved documents → the bot sends the result to the chat. The conversation history is saved in KV to provide context between messages. This lets the bot remember earlier questions and refine its answers depending on the context of the conversation. Notably, Groq was not chosen at random. It is a fa

What stack you need?

The implementation needs a minimal set of components: TypeScript — the language the whole codebase is written in, with type support Telegraf — a lightweight and popular library for working with the Telegram API Cloudflare Workers — a serverless platform for deployment (free plan with generous limits) Cloudflare KV — built-in storage for the knowledge base and conversation history Groq API — a free LLM service for generating answers from the retrieved documents Deployment takes a single command through Wrangler, the CLI tool for Cloudflare Workers. There is no server setup,

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…