Files
embed/src/hash.ts
T
xiaomo 396e005686 feat: embedding service — Cloudflare Worker + KV cache + Dashscope
- POST /embed: batch text → vector (max 100)
- KV cache: sha256(model+text), content-addressable, no expiry
- Dashscope text-embedding-v3 upstream (1024 dims)
- Bearer token auth
- Health endpoint

Deployed: https://embed.shazhou.workers.dev
2026-04-29 07:21:46 +00:00

11 lines
420 B
TypeScript

/**
* SHA-256 hash using Web Crypto API (available in Workers runtime).
*/
export async function createHash(input: string): Promise<string> {
const encoder = new TextEncoder();
const data = encoder.encode(input);
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
}