Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

Vectorize MCP Worker (Python)

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge in Python.

Table of Contents

Features

  • Hybrid Search (Vector + BM25) with Reciprocal Rank Fusion
  • Multimodal Image Processing (Llama 4 Scout)
  • Cross-Encoder Reranking (bge-reranker-base)
  • Recursive Chunking with 15% overlap
  • One-time License System
  • Interactive Dashboard at /dashboard
  • MCP tool integration (via vectorize-mcp-tool package)

Setup

Prerequisites

  • A Cloudflare account with Workers, Vectorize, D1, and Workers AI enabled
  • uv (Python package manager)
  • wrangler (Cloudflare CLI) -- needed to create cloud resources

Install uv

macOS:

brew install uv

Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install Wrangler (Cloudflare CLI)

Wrangler is needed to create and manage Cloudflare resources (D1 databases, Vectorize indexes, secrets). Install it globally via npm:

macOS:

brew install node # if you don't have Node.js
npm install -g wrangler

Linux (Debian/Ubuntu):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g wrangler

Linux (any distro, via nvm):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source~/.bashrc # or restart your shell
nvm install --lts
npm install -g wrangler

Then authenticate with your Cloudflare account:

wrangler login

This opens a browser window to authorize the CLI against your account.

Install Python Dependencies

uv init
uv tool install workers-py

Create Cloudflare Resources

The project requires three Cloudflare services: Vectorize (vector database), D1 (SQL database), and Workers AI (inference). Workers AI is enabled automatically; the other two need to be created. A fourth service, multimodal-pro-worker, is optional and enables image features.

1. Create the Vectorize Index

This creates the vector store used for semantic search with 384-dimension BGE embeddings:

wrangler vectorize create mcp-knowledge-base --dimensions=384 --metric=cosine

2. Create the D1 Database

D1 stores document metadata, BM25 keyword indexes, and license records:

wrangler d1 create mcp-knowledge-db

This outputs a database ID. Copy it and update wrangler.toml:

[[d1_databases]]
binding = "DB"database_name = "mcp-knowledge-db"database_id = "paste-your-database-id-here"

3. Apply the Database Schema

Run the schema migration against the remote D1 database:

wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql

This creates the following tables:

TablePurpose
documentsIngested document chunks and metadata
keywordsBM25 term-frequency index per document
doc_statsCorpus-level statistics (total docs, avg length)
term_statsDocument-frequency per term
licensesAPI license keys and quotas

4. Set the API Key Secret

Set the API key that protects write operations (/ingest/document, /license/*):

wrangler secret put API_KEY

You will be prompted to enter the secret value interactively. This is stored encrypted and never appears in wrangler.toml.

5. Deploy the Multimodal Worker (optional -- for image features)

The image endpoints (/ingest/image, /search/similar-images) require a separate worker that processes images via Llama 4 Scout. If you only need text search, skip this step.

cd multimodal-pro-worker
uv tool install workers-py # if not already installed
uv run pywrangler deploy
cd ..

This deploys the multimodal-pro-worker which the main worker calls via a Service Binding. Without it, text features work normally and image endpoints return a 501 error with a clear message.

Deploy and Debug

Build and deploy to Cloudflare's global edge network:

uv run pywrangler deploy

Stream live logs from the deployed worker:

wrangler tail --format=json

For a complete step-by-step guide, see docs/quickstart.md. For production deployment, security, and monitoring, see docs/production.md.

API Endpoints

EndpointMethodDescription
/GETAPI documentation
/health/checkGETHealth check
/dashboardGETInteractive playground UI
/llms.txtGETAI search engine info
/stats/indexGETIndex statistics
/search/multimodalPOSTHybrid search (documents + images)
/search/documentsPOSTDocuments-only search
/search/similar-imagesPOSTFind similar images
/ingest/documentPOSTDocument ingestion
/ingest/imagePOSTImage ingestion (requires multimodal-pro-worker)
/get/document/:idGETGet document by ID
/get/image/:idGETGet image by ID
/list/documentsGETList documents
/delete/document/:idDELETEDelete document
/delete/license/:keyDELETEDelete license
/license/validatePOSTValidate license
/license/createPOSTCreate license
/license/listGETList licenses
/license/revokePOSTRevoke license
/init/reset-passphrasePOSTSet passphrase for reset endpoints
/reset/allPOSTReset all (passphrase-gated)
/reset/documentsPOSTReset documents (passphrase-gated)
/reset/licensesPOSTReset licenses (passphrase-gated)

Search results return snippets and metadata instead of full content. The passphrase-gated reset endpoints (/init/reset-passphrase, /reset/*) prevent accidental AI deletion.

MCP Integration

All MCP operations are performed through the vectorize-mcp-tool package, which provides both a CLI and a FastMCP stdio server. The MCP tool dispatches directly to the worker's REST endpoints -- there are no /mcp/* proxy endpoints on the worker.

Operations: search_multimodal, search_documents, ingest, ingest_image, stats, delete, get_document, get_image, list_documents, license_validate, license_create, license_list, license_revoke, delete_license, reset_all, reset_documents, reset_licenses.

Install and Use

# Installcd vectorize-mcp-tool && pip install -e .# CLI usage
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY health
vectorize-mcp --url https://your-worker.workers.dev --api-key YOUR_KEY search multimodal "your query"# MCP server for Cursor
vectorize-mcp-server # reads VECTORIZE_URL and VECTORIZE_API_KEY from env

See vectorize-mcp-tool/README.md for full documentation.

Project Structure

vectorize-mcp-worker-python/
├── src/ # Main worker source
│ ├── entry.py # HTTP routing and Worker entrypoint
│ ├── bindings/ # Cloudflare binding wrappers (FFI)
│ ├── hybrid_search.py # Vector + BM25 + RRF fusion
│ ├── ingestion.py # Document/image ingestion pipeline
│ └── ...
├── multimodal-pro-worker/ # Separate worker for image processing
│ ├── src/entry.py # Llama 4 Scout vision + OCR + embedding
│ └── wrangler.toml # Independent worker config
├── vectorize-mcp-tool/ # CLI + MCP server package
│ ├── src/vectorize_mcp_tool/ # Client, server, CLI
│ └── tests/ # MCP tool unit tests
├── tests/ # Test suite
│ ├── unit/ # Unit tests (no network)
│ ├── integration/ # Contract tests (worker <-> MCP tool sync)
│ └── e2e/ # E2E tests + benchmarks (live worker)
├── schema.sql # D1 database DDL
├── wrangler.toml.example # Template config (copy to wrangler.toml)
└── docs/ # All documentation

Testing

# Unit tests (no network, fast)
uv run pytest tests/unit/ --cov=src --cov-report=term-missing
# Integration/contract tests (no network)
uv run pytest tests/integration/
# MCP tool testscd vectorize-mcp-tool && uv run pytest tests/
# E2E tests (requires live worker)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m "not benchmark"# Benchmarks (persists results, detects regressions)
VECTORIZE_E2E_URL=https://... VECTORIZE_E2E_API_KEY=... uv run pytest tests/e2e/ -m benchmark

Contract tests in tests/integration/ verify that the worker and MCP tool stay in sync. Any endpoint change in the worker that isn't reflected in the MCP tool will fail these tests.

Architecture

See docs/ for detailed documentation:

  • docs/quickstart.md -- Step-by-step first-time setup and endpoint testing
  • docs/production.md -- Production deployment, security, monitoring, operations
  • docs/abstraction_layers.md -- Protocol design and FFI patterns

About

Production-Grade Hybrid RAG with Multimodal Support on Cloudflare Edge

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages