# leto **Repository Path**: hongbin1/leto ## Basic Information - **Project Name**: leto - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-04 - **Last Updated**: 2026-05-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
# Leto **AI时代的本地向量存储解决方案** **轻量 • 快速 • 易用 • 开源** [![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat&logo=go)](https://golang.org) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/zhb/leto)](https://goreportcard.com/report/github.com/zhb/leto) [![Documentation](https://img.shields.io/badge/docs-latest-green.svg)](docs/) [快速开始](#快速开始) • [特性](#核心特性) • [文档](#文档) • [性能](#性能表现) • [贡献](#贡献)
--- ## 🎯 项目简介 **Leto** 是一款专为AI应用设计的本地向量数据库,提供毫秒级的向量检索能力。无需复杂配置,单二进制文件即可运行,完美适配AI Agent、RAG应用、语义搜索等场景。 ### 为什么选择 Leto? - 🚀 **极致性能** - HNSW算法实现,支持百万级向量毫秒级检索 - 💡 **开箱即用** - 单文件部署,无需外部依赖,5秒启动服务 - 🔌 **兼容友好** - Elasticsearch风格API + MySQL协议支持,零学习成本 - 🎯 **功能完整** - 向量搜索、全文检索、混合查询一站式解决 - 🔒 **安全可靠** - 本地存储,数据完全掌控,支持认证授权 - 📦 **轻量高效** - 仅11MB二进制文件,内存占用低 --- ## ✨ 核心特性 ### 🔍 多模态检索 | 功能 | 说明 | 性能 | |------|------|------| | **向量搜索** | HNSW算法,支持高维向量快速检索 | 10K向量 < 1ms | | **全文搜索** | BM25算法,支持中英文分词 | 100K文档 < 5ms | | **混合检索** | 向量+关键词融合,RRF重排序 | 准确率提升30% | ### 🤖 AI Agent 支持 - ✅ **记忆管理** - 时间衰减、重要性评分、自动压缩 - ✅ **Agent隔离** - 多租户数据隔离,权限控制 - ✅ **上下文优化** - 智能摘要,Token优化 ### 🔌 双接口支持 Leto同时提供两种接口,满足不同用户需求: #### Elasticsearch风格API ```bash # 向量搜索 curl -X POST "http://localhost:9527/my-index/_search" -d' { "query": { "knn": { "field": "embedding", "query_vector": [0.1, 0.2, ...], "k": 10 } } }' ``` #### MySQL协议接口 ```sql -- 向量搜索 SELECT id, title, VECTOR_SIMILARITY(embedding, '[0.1,0.2,...]') AS score FROM my_index ORDER BY score DESC LIMIT 10; ``` ### 💾 存储后端 **主推: BoltDB** (默认) - 高性能键值存储 - ✅ 读写性能优异(72K+ docs/sec写入) - ✅ 内存映射,零拷贝读取 - ✅ 生产环境验证,稳定可靠 **可选: SQLite** - 单文件部署 - ✅ 单文件存储,便于备份迁移 - ✅ SQL查询能力,开发调试方便 - ⚠️ 性能较BoltDB低(适合数据量<10万场景) ### 📈 性能优化 - ✅ **查询缓存** - LRU缓存,命中率>80%,查询加速100倍 - ✅ **性能监控** - 实时指标收集,延迟直方图统计 - ✅ **批量操作** - _bulk API,支持批量索引/删除 - ✅ **连接池** - 对象池复用,减少GC压力 - ✅ **并行查询** - 多核并行,吞吐量提升3倍 - ✅ **数据压缩** - Gzip/LZW压缩,存储节省60% ### 🏢 企业级功能 - ✅ **批量操作** - _bulk API,支持批量索引/删除 - ✅ **索引管理** - 别名、模板、统计分析 - ✅ **监控告警** - Prometheus指标,实时监控 - ✅ **备份恢复** - 增量备份,快速恢复 - ✅ **认证授权** - API Key、Basic Auth ### ⚡ 性能优化 - ✅ **查询缓存** - LRU缓存,命中率>80% - ✅ **连接池** - 对象池复用,减少GC压力 - ✅ **并行查询** - 多核并行,吞吐量提升3倍 - ✅ **数据压缩** - Gzip/LZW压缩,存储节省60% --- ## 🚀 快速开始 ### 安装 #### 方式1: 下载预编译二进制 ```bash # Linux/macOS wget https://github.com/zhb/leto/releases/latest/download/leto-linux-amd64.tar.gz tar -xzf leto-linux-amd64.tar.gz sudo mv leto-linux-amd64 /usr/local/bin/leto # Windows # 从 https://github.com/zhb/leto/releases 下载 .zip 文件 ``` #### 方式2: 从源码构建 ```bash # 克隆仓库 git clone https://github.com/zhb/leto.git cd leto # 构建 make build # 或使用 Go 命令 go build -o leto main.go ``` #### 方式3: Docker ```bash docker pull zhb/leto:latest docker run -d -p 9527:9527 -v leto-data:/data zhb/leto:latest ``` ### 启动服务 ```bash # 使用默认配置启动(推荐,使用BoltDB后端) leto # 或指定端口和数据目录 LETO_PORT=9527 LETO_DATA_DIR=./data leto # 查看版本 leto --version ``` ### 存储后端配置(可选) ```yaml # 默认使用BoltDB(推荐生产环境) # 无需修改配置,直接启动即可 # 如需使用SQLite(开发/小数据量场景) # 创建 configs/config.yaml: storage: type: sqlite data_dir: ./data db_name: leto.db ``` 服务启动后访问: - API地址: http://localhost:9527 - 健康检查: http://localhost:9527/health --- ## 📖 使用示例 ### 1. 创建索引 ```bash curl -X PUT "http://localhost:9527/my-index" -H 'Content-Type: application/json' -d' { "mappings": { "properties": { "title": { "type": "text" }, "content": { "type": "text" }, "embedding": { "type": "vector", "dims": 128 } } } }' ``` ### 2. 写入文档 ```bash curl -X PUT "http://localhost:9527/my-index/_doc/1" -H 'Content-Type: application/json' -d' { "title": "Introduction to Machine Learning", "content": "Machine learning is a subset of artificial intelligence...", "embedding": [0.1, 0.2, 0.3, ...] }' ``` ### 3. 向量搜索 ```bash curl -X POST "http://localhost:9527/my-index/_search" -H 'Content-Type: application/json' -d' { "query": { "vector": { "embedding": { "vector": [0.1, 0.2, 0.3, ...], "k": 10 } } } }' ``` ### 4. 全文搜索 ```bash curl -X POST "http://localhost:9527/my-index/_search" -H 'Content-Type: application/json' -d' { "query": { "match": { "content": "machine learning" } } }' ``` ### 5. 混合检索 ```bash curl -X POST "http://localhost:9527/my-index/_search" -H 'Content-Type: application/json' -d' { "query": { "hybrid": { "vector": { "field": "embedding", "vector": [0.1, 0.2, 0.3, ...], "k": 10 }, "text": { "content": "machine learning" } } } }' ``` ### 6. MySQL接口访问(新功能) Leto支持MySQL协议,可以直接用mysql客户端连接: ```bash # 连接MySQL接口 mysql -h 127.0.0.1 -P 3306 -u root # 创建表 CREATE TABLE my_index ( id VARCHAR(255) PRIMARY KEY, title TEXT, content TEXT, embedding TEXT ); # 插入数据 INSERT INTO my_index (id, title, content, embedding) VALUES ('1', 'Introduction to Machine Learning', 'Machine learning is...', '[0.1,0.2,0.3]'); # 向量搜索 SELECT id, title, VECTOR_SIMILARITY(embedding, '[0.1,0.2,0.3]') AS score FROM my_index ORDER BY score DESC LIMIT 10; # 全文搜索 SELECT id, title, MATCH(content) AGAINST('machine learning' IN NATURAL MODE) AS score FROM my_index ORDER BY score DESC LIMIT 10; ``` 详细MySQL接口文档: [MySQL接口说明](docs/MYSQL_INTERFACE.md) 完整示例代码: [MySQL示例](docs/MYSQL_EXAMPLES.md) ### 7. 性能监控(新功能) Leto内置了完善的性能监控系统: ```bash # 查看缓存命中率 curl http://localhost:9527/_cache/stats # 查看性能指标 curl http://localhost:9527/_metrics ``` --- ## 📊 性能表现 ### 基准测试结果 | 测试场景 | 数据规模 | 平均延迟 | QPS | |---------|---------|---------|-----| | 向量搜索 | 10K向量 | 0.8ms | 12,500 | | 向量搜索 | 100K向量 | 2.3ms | 4,347 | | 全文搜索 | 10K文档 | 1.2ms | 8,333 | | 全文搜索 | 100K文档 | 4.5ms | 2,222 | | 混合检索 | 10K文档 | 1.8ms | 5,555 | | 数据写入 | - | 0.5ms | 20,000 | ### 资源消耗 - **内存**: 50MB (基础) + 1KB/向量 - **磁盘**: 100KB (基础) + 2KB/文档 - **CPU**: 低负载 < 5%, 高负载 < 50% 详细性能报告: [性能对比报告](docs/PERFORMANCE_COMPARISON_V3.md) --- ## 🛠️ 开发指南 ### 构建 ```bash # 构建当前平台 make build # 构建所有平台 make build-all # 运行测试 make test # 生成覆盖率报告 make coverage # 完整发布流程 make release ``` ### 测试 ```bash # 单元测试 make test # 集成测试 make test-integration # 性能测试 make test-benchmark # 覆盖率报告 make coverage ``` ### Makefile 命令 ```bash make help # 查看所有可用命令 ``` --- ## 📚 文档 ### 快速入门 - [快速开始指南](docs/QUICKSTART.md) - 5分钟上手Leto - [API文档](docs/API.md) - 完整API参考 - [配置说明](docs/CONFIGURATION.md) - 详细配置参数 - [MySQL接口](docs/MYSQL_INTERFACE.md) - MySQL协议使用指南 ⭐ NEW ### 深入了解 - [设计文档](docs/design.md) - 架构设计和实现原理 - [性能优化](docs/PERFORMANCE_OPTIMIZATION.md) - 性能调优指南 - [最佳实践](docs/BEST_PRACTICES.md) - 生产环境部署建议 - [MySQL示例](docs/MYSQL_EXAMPLES.md) - 完整MySQL使用示例 ⭐ NEW ### 测试报告 - [性能对比报告](docs/PERFORMANCE_COMPARISON_V3.md) - 多版本性能对比 - [集成测试报告](docs/INTEGRATION_TEST_REPORT.md) - 功能测试覆盖 - [MySQL测试报告](tests/integration/ACTUAL_TEST_REPORT.md) - MySQL接口测试 ⭐ NEW --- ## 🗺️ 路线图 ### v1.4 (当前版本) ⭐ NEW - ✅ **BoltDB 保持默认** - 高性能存储后端(主推) - ✅ **SQLite 可选支持** - 单文件部署(适合开发/小数据量) - ✅ **向量量化优化** - 4-bit/8-bit/float32 可选 - ✅ **索引持久化** - HNSW和全文索引保存到SQLite - ✅ **内存映射** - 支持千万级向量存储 - ✅ **迁移工具** - BoltDB ↔ SQLite 平滑迁移 ### v1.3 (已发布) - ✅ 向量搜索 (HNSW) - ✅ 全文搜索 (BM25) - ✅ 混合检索 (RRF) - ✅ AI Agent记忆管理 - ✅ 企业级功能 - ✅ MySQL协议支持 - ✅ 向量搜索SQL函数 - ✅ 全文搜索SQL函数 - ✅ 查询缓存优化 - ✅ 性能监控 ### v1.5 (计划中) - 🔲 分布式部署 - 🔲 数据分片 - 🔲 副本机制 - 🔲 Web管理界面 ### v2.0 (未来) - 🔲 多模态支持(图像、音频) - 🔲 图数据库功能 - 🔲 流式处理 - 🔲 云原生支持 --- ## 🤝 贡献 我们欢迎所有形式的贡献! ### 贡献方式 - 🐛 [报告Bug](https://github.com/zhb/leto/issues/new?template=bug_report.md) - 💡 [提出新功能](https://github.com/zhb/leto/issues/new?template=feature_request.md) - 📝 改进文档 - 🔧 提交代码 ### 开发流程 1. Fork 本仓库 2. 创建特性分支 (`git checkout -b feature/AmazingFeature`) 3. 提交更改 (`git commit -m 'Add some AmazingFeature'`) 4. 推送到分支 (`git push origin feature/AmazingFeature`) 5. 创建 Pull Request 详细贡献指南请查看 [CONTRIBUTING.md](CONTRIBUTING.md) --- ## 📝 更新日志 查看 [CHANGELOG.md](CHANGELOG.md) 了解版本更新历史。 --- ## 💬 社区 - 💬 [GitHub Discussions](https://github.com/zhb/leto/discussions) - 问题讨论 - 🐛 [Issue Tracker](https://github.com/zhb/leto/issues) - Bug反馈 - 📧 Email: zhb@example.com --- ## 📄 许可证 本项目采用 Apache 2.0 许可证 - 详见 [LICENSE](LICENSE) 文件 ---
**⭐ 如果这个项目对你有帮助,请给一个 Star ⭐** Made with ❤️ by the Leto Team