TideRAG

@carloscortezcloud/tiderag

RAG pipeline on Cloudflare free tier. Ingest documents → embed with Workers AI → store in Vectorize → query in ~20ms. $0/month.

TideRAG

Requires Cloudflare Workers bindings for Vectorize, Workers AI, and D1.

import { TideRAG } from '@carloscortezcloud/tiderag';

const rag = new TideRAG({
  vectorize: env.VECTORIZE_INDEX,  // CF Vectorize binding
  ai: env.AI,                      // CF Workers AI binding
  d1: env.DB,                      // CF D1 database binding
  embeddingModel: '@cf/baai/bge-base-en-v1.5',  // Optional: default
});

Methods

rag.ingest({ content, metadata?, chunkStrategy? })

Ingest a document. Chunks, embeds, and stores in Vectorize + D1.

await rag.ingest({
  content: '## Introduction\nTinkuy Labs is...',  'docs/intro.md' },  // Optional: any JSON
  chunkStrategy: 'markdown',                  // 'markdown' | 'paragraph' | 'sliding'
});
rag.query(query, { topK?, filter? })

Query the vector index. Returns ranked chunks.

const results = await rag.query(
  'How do I deploy to Workers?',
  { topK: 5 }
);
// → [{ text: '## Deploy\nUse wrangler deploy...', score: 0.87, metadata }]

Chunking Strategies

markdown

Split by headers (##, ###). Best for documentation and structured content. Preserves section hierarchy.

paragraph

Split by double newlines. Best for articles, blog posts, and prose.

sliding

Fixed window with configurable overlap. Best for unstructured text. Parameters: chunkSize (default 512), overlap (default 64).

Wrangler Configuration

Add these bindings to your wrangler.jsonc:

{
  "vectorize": [
    { binding: "VECTORIZE_INDEX", index_name: "my-index" }
  ],
  "ai": [
    { binding: "AI" }  // Workers AI (free embeddings)
  ],
  "d1_databases": [
    { binding: "DB", database_name: "rag-metadata", database_id: "..." }
  ]
}

Use as Agent Tool

Wrap TideRAG in a Tinkuy tool for agentic RAG:

import { defineTool } from '@carloscortezcloud/tinkuy-agent';
import { TideRAG } from '@carloscortezcloud/tiderag';

const searchKnowledge = defineTool({
  name: 'search_knowledge',
  description: 'Search documentation for answers',
  parameters: {
    type: 'object',
    properties: {
      question: { type: 'string', description: 'User question' },
    },
    required: ['question'],
  },
  execute: async (args) => {
    const results = await rag.query(args.question, { topK: 3 });
    return results.map(r => r.text).join('\n---\n');
  },
});

Free Tier Limits

ServiceFree LimitCost if exceeded
Vectorize5M vectors$0.50/M vectors
Workers AI10K embeddings/day~$0.001/1K
D15GB storage$0.75/GB