{"id":22272663,"url":"https://github.com/ourines/cloudflare-vectorize","last_synced_at":"2025-07-28T14:31:44.874Z","repository":{"id":265519937,"uuid":"880389970","full_name":"ourines/cloudflare-vectorize","owner":"ourines","description":"A Python client library for Cloudflare Vectorize API, providing vector database operations with comprehensive error handling, retry mechanisms, and type hints support.","archived":false,"fork":false,"pushed_at":"2024-10-29T16:53:03.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-29T18:50:44.860Z","etag":null,"topics":["api-client","cloudflare","embeddings","python","vectorize"],"latest_commit_sha":null,"homepage":"https://github.com/ourines/cloudflare-vectorize","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ourines.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-29T16:29:04.000Z","updated_at":"2024-11-12T04:05:49.000Z","dependencies_parsed_at":"2024-11-29T18:50:48.802Z","dependency_job_id":"7bb76fbf-8d26-4984-b6a8-0a47a3655e4a","html_url":"https://github.com/ourines/cloudflare-vectorize","commit_stats":null,"previous_names":["ourines/cloudflare-vectorize"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourines%2Fcloudflare-vectorize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourines%2Fcloudflare-vectorize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourines%2Fcloudflare-vectorize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourines%2Fcloudflare-vectorize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ourines","download_url":"https://codeload.github.com/ourines/cloudflare-vectorize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227923053,"owners_count":17840940,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","cloudflare","embeddings","python","vectorize"],"created_at":"2024-12-03T13:07:58.522Z","updated_at":"2024-12-03T13:07:59.319Z","avatar_url":"https://github.com/ourines.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloudflare Vectorize Python Client\n\n一个用于与 Cloudflare Vectorize API 交互的 Python 客户端。\n\n## 特性\n\n- 完整支持 Cloudflare Vectorize API\n- 类型提示支持\n- 完善的错误处理\n- 可配置的重试机制\n- 详细的文档\n\n## 安装\n\n```bash\npip install cloudflare-vectorize\n```\n\n## 快速开始\n\n```python\nfrom cloudflare_vectorize import CloudflareVectorize\n\n# 初始化客户端\nclient = CloudflareVectorize(\n    account_id=\"your-account-id\",\n    auth_config={\n        \"bearer_token\": \"your-bearer-token\"\n        # 或者使用 API key 认证:\n        # \"auth_email\": \"your-email\",\n        # \"auth_key\": \"your-api-key\"\n    },\n    retry_config={\n        \"total\": 3,  # 最大重试次数\n        \"backoff_factor\": 0.1,  # 重试间隔系数\n        \"status_forcelist\": [500, 502, 503, 504]  # 需要重试的状态码\n    }\n)\n\n# 创建索引\nresponse = client.create_index(\n    name=\"example-index\",\n    dimensions=768,\n    metric=\"cosine\",\n    description=\"Example vector index\"\n)\n\n# 插入向量\nvectors_data = \"\"\"\n{\"id\": \"vec1\", \"values\": [0.1, 0.2, 0.3], \"metadata\": {\"category\": \"test\"}}\n{\"id\": \"vec2\", \"values\": [0.4, 0.5, 0.6], \"metadata\": {\"category\": \"test\"}}\n\"\"\"\nresponse = client.insert_vectors(\"example-index\", vectors_data)\n\n# 查询向量\nresponse = client.query_vectors(\n    index_name=\"example-index\",\n    vector=[0.1, 0.2, 0.3],\n    top_k=2,\n    filter={\"category\": \"test\"},\n    return_metadata=\"all\"\n)\n```\n\n## API 参考\n\n### 索引管理\n\n```python\n# 列出所有索引\nclient.list_indexes()\n\n# 创建索引\nclient.create_index(\n    name=\"example-index\",\n    dimensions=768,\n    metric=\"cosine\",\n    description=\"Example index\"\n)\n\n# 获取索引信息\nclient.get_index(\"example-index\")\n\n# 获取索引统计信息\nclient.get_index_info(\"example-index\")\n\n# 删除索引\nclient.delete_index(\"example-index\")\n```\n\n### 向量操作\n\n```python\n# 插入向量\nvectors_data = \"\"\"\n{\"id\": \"vec1\", \"values\": [0.1, 0.2, 0.3]}\n{\"id\": \"vec2\", \"values\": [0.4, 0.5, 0.6]}\n\"\"\"\nclient.insert_vectors(\"example-index\", vectors_data)\n\n# 更新或插入向量\nclient.upsert_vectors(\"example-index\", vectors_data)\n\n# 查询向量\nclient.query_vectors(\n    index_name=\"example-index\",\n    vector=[0.1, 0.2, 0.3],\n    top_k=5,\n    filter={\"category\": \"test\"},\n    return_metadata=\"all\",\n    return_values=True\n)\n\n# 获取向量\nclient.get_vectors(\"example-index\", [\"vec1\", \"vec2\"])\n\n# 删除向量\nclient.delete_vectors(\"example-index\", [\"vec1\", \"vec2\"])\n```\n\n### 元数据索引\n\n```python\n# 创建元数据索引\nclient.create_metadata_index(\n    index_name=\"example-index\",\n    property_name=\"category\",\n    index_type=\"string\"\n)\n\n# 列出元数据索引\nclient.list_metadata_indexes(\"example-index\")\n\n# 删除元数据索引\nclient.delete_metadata_index(\"example-index\", \"category\")\n```\n\n### 错误处理\n\n```python\nfrom cloudflare_vectorize import CloudflareVectorizeError, APIError\n\ntry:\n    response = client.query_vectors(\n        index_name=\"example-index\",\n        vector=[0.1, 0.2, 0.3]\n    )\nexcept APIError as e:\n    print(f\"API错误: {e}\")\n    print(f\"错误详情: {e.errors}\")\nexcept CloudflareVectorizeError as e:\n    print(f\"客户端错误: {e}\")\n```\n\n## 开发\n\n```bash\n# 克隆仓库\ngit clone https://github.com/ourines/cloudflare-vectorize.git\ncd cloudflare-vectorize\n\n# 创建虚拟环境\npython -m venv venv\nsource venv/bin/activate  # Windows: venv\\Scripts\\activate\n\n# 安装开发依赖\npip install -e \".[dev]\"\n\n# 运行测试\npytest\n```\n\n## 许可证\n\nMIT License\n\n## 作者\n\nourines (ourines@icloud.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fourines%2Fcloudflare-vectorize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fourines%2Fcloudflare-vectorize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fourines%2Fcloudflare-vectorize/lists"}