A vector search API for legal documents powered by Cloudflare Workers, D1, and Vectorize. This API allows you to submit legal documents, search through them semantically, and get AI-powered answers to legal questions.
- Document submission with automatic text chunking and embedding
- Semantic search across documents
- AI-powered question answering using the document context
- Namespace support for document organization
- Built on Cloudflare's edge infrastructure
- Clone this repository
- Set up a Cloudflare Page with their admin
- Run the setup commands:
pnpm
pnpm setup-cloudflare
pnpm load-schema
OPENAI_API_KEY
: Your OpenAI API keyAUTH_SECRET
: A secret used to authenticate requests to the API (optional)
curl -X GET "http://localhost:8787/documents/search" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-auth-secret" \
-d '{
"query": "your search query",
"namespace": "default"
}'
curl -X POST "http://localhost:8787/documents" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-auth-secret" \
-d '{
"url": "https://example.com/document",
"text": "Your document text here",
"namespace": "default"
}'
curl -X POST "http://localhost:8787/documents/suggest" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-auth-secret" \
-d '{
"query": "document title search",
"namespace": "default"
}'
curl -X GET "http://localhost:8787/documents/123" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-auth-secret"
curl -X POST "http://localhost:8787/chat" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-auth-secret" \
-d '{
"query": "your question about the documents",
"namespace": "default"
}'
curl -X POST "http://localhost:8787/chat/suggest" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-auth-secret" \
-d '{
"query": "your question for document suggestions",
"namespace": "default"
}'
Run the development server:
pnpm dev
pnpm setup-cloudflare
pnpm load-schema --remote