内容
<h1 align="center">
<a href="https://github.com/AmanSagar0607/Context-OS">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/AmanSagar0607/Context-OS/main/public/context-os-banner-dark.svg">
<img alt="Context OS - Context Infrastructure for AI Agents" src="https://raw.githubusercontent.com/AmanSagar0607/Context-OS/main/public/context-os-banner.svg" width="100%">
</picture>
</a>
</h1>
<p align="center">
<a href="https://github.com/AmanSagar0607/Context-OS/stargazers" target="_blank"><img src="https://img.shields.io/github/stars/AmanSagar0607/Context-OS?style=social" alt="GitHub stars"></a>
<a href="https://github.com/AmanSagar0607/Context-OS/network/members" target="_blank"><img src="https://img.shields.io/github/forks/AmanSagar0607/Context-OS?style=social" alt="GitHub forks"></a>
<a href="https://github.com/AmanSagar0607/Context-OS/watchers" target="_blank"><img src="https://img.shields.io/github/watchers/AmanSagar0607/Context-OS?style=social" alt="GitHub watchers"></a>
<a href="https://github.com/AmanSagar0607/Context-OS/issues" target="_blank"><img src="https://img.shields.io/github/issues/AmanSagar0607/Context-OS?style=social" alt="GitHub issues"></a>
<br/>
<a href="https://github.com/AmanSagar0607/Context-OS/blob/main/LICENSE" alt="License">
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-blue.svg"></a>
<a href="https://python.org" alt="Python 3.11+">
<img alt="Python 3.11+" src="https://img.shields.io/badge/Python-3.11+-green.svg"></a>
<a href="https://github.com/AmanSagar0607/Context-OS/actions" alt="Tests">
<img alt="Tests" src="https://github.com/AmanSagar0607/Context-OS/actions/workflows/tests.yml/badge.svg"></a>
<a href="https://github.com/AmanSagar0607/Context-OS/pkgs/context-core" alt="Package">
<img alt="Package" src="https://img.shields.io/badge/package-context--core-blue"></a>
<br/>
<a href="https://discord.gg/YrSpR43UB" alt="Discord" target="_blank">
<img alt="Discord" src="https://img.shields.io/discord/1517250412506513609?style=social&logo=discord&logoColor=white"></a>
<a href="https://x.com/AmanSagar0607a" alt="X (formerly Twitter)" target="_blank">
<img alt="X (formerly Twitter) Follow" src="https://img.shields.io/twitter/follow/AmanSagar0607a?style=social&logo=x"></a>
<a href="https://github.com/AmanSagar0607" alt="GitHub" target="_blank">
<img alt="GitHub followers" src="https://img.shields.io/github/followers/AmanSagar0607?style=social&logo=github"></a>
<a href="https://amansagar.in" alt="Website" target="_blank">
<img alt="Website" src="https://img.shields.io/badge/🌐-amansagar.in-blue?style=social"></a>
<br/>
<a href="https://github.com/AmanSagar0607/Context-OS" alt="PRs Welcome">
<img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a>
</p>
<p align="center">
<a href="https://docs.contextos.dev/quickstart"><strong>快速开始</strong></a>
·
<a href="https://docs.contextos.dev/api"><strong>API 参考</strong></a>
·
<a href="https://docs.contextos.dev/sdk"><strong>软件开发工具包</strong></a>
·
<a href="https://docs.contextos.dev/mcp"><strong>MCP</strong></a>
·
<a href="https://docs.contextos.dev/self-hosting"><strong>自托管</strong></a>
</p>
<p align="center">
<b>人工智能终于可以记住。</b> 开源的上下文基础设施,为人工智能代理提供记忆、网络智能和结构化知识 — 通过单个API和MCP服务器。
</p>
<p align="center">
<a href="https://amansagar.in" target="_blank">🌐 网站</a> ·
<a href="https://x.com/AmanSagar0607a" target="_blank">𝕏 推特</a> ·
<a href="https://discord.gg/YrSpR43UB" target="_blank">💬 Discord</a> ·
<a href="https://github.com/AmanSagar0607" target="_blank">GitHub</a> ·
<a href="https://linkedin.com/in/amansagar0607" target="_blank">LinkedIn</a>
</p>
---
<p align="center">
<a href="https://github.com/sponsors/AmanSagar0607" target="_blank" style="display:flex; justify-content:center; padding:4px 0;">
<img src="https://img.shields.io/badge/Become_a-Sponsor-FF4500?style=for-the-badge&logo=githubsponsors&logoColor=white" alt="Become a Sponsor">
</a>
</p>
---
## 为什么选择Context OS?
每个AI应用程序最终都需要:
- **记忆** — 以便代理记住会话
- **上下文** — 以便响应相关且有依据
- **检索** — 以便知识可访问且准确
- **知识** — 以便理解关系
- **搜索** — 以便信息当前且完整
今天,这些功能分散在多个工具中。你需要将Mem0用于记忆,Firecrawl用于爬取,矢量数据库用于搜索,并使用自定义代码构建知识图谱。
**Context OS 将它们统一到一个开发人员平台中。**
```python
from context_ai import ContextAI, MemoryCreate, MemoryType, ImportanceLevel
client = ContextAI(api_key="...")
# 存储记忆
memory = client.memory.add(MemoryCreate(
content="用户偏好暗色模式和简洁的回复",
memory_type=MemoryType.SEMANTIC,
importance=ImportanceLevel.HIGH,
tags=["preference", "ui"],
))
# 搜索记忆
results = client.memory.search(query="用户有哪些UI偏好?")
# 获取上下文窗口
context = client.memory.context(query="我应该了解这个用户什么?")
# 爬取和提取知识
page = client.crawl.scrape(url="https://example.com/article")
# 网络搜索
results = client.search.web(query="AI初创公司 2026")
```
---
## 主要功能
### 统一记忆系统
- **持久化代理记忆** 跨会话和对话
- **语义搜索** 使用pgvector余弦相似度
- **多种记忆类型**:情景、语义、过程
- **重要性级别** 用于记忆巩固
- **上下文窗口** 由相关记忆组装
### 混合检索管道
- **矢量搜索** 通过pgvector
- **BM25搜索** 通过PostgreSQL FTS
- **互惠排名融合** 用于组合结果
- **查询扩展** (HyDE, 多查询)
- **重新排序** 使用交叉编码器
### 网络智能
- **多提供者爬取** 带有备用链(Crawl4AI → Jina → httpx)
- **5提供者搜索** (Tavily → Brave → SearXNG → DuckDuckGo → Google)
- **Playwright浏览器自动化** 用于JS渲染页面
- **AI提取** 用于从非结构化内容中提取结构化数据
### 知识图谱
- **实体提取** 从爬取内容
- **关系映射** 实体之间
- **语义搜索** 在知识图谱上
- **记忆-实体连接** 用于上下文
### MCP本地
- **20种工具**,分为4组:记忆、搜索、爬取、知识
- **JSON-RPC 2.0** 兼容
- **HTTP/SSE传输** 用于远程服务器
- **stdio传输** 用于本地开发
- 与Claude、Cursor和任何MCP客户端配合使用
### 开发体验
- **Python SDK** — 异步优先,类型安全
- **TypeScript SDK** — 完整的类型覆盖
- **CLI工具** — 从终端管理一切
- **REST API** — 25+ 端点
- **OpenAPI规范** — 自动生成
---
## 入门指南
### 先决条件
- Python 3.11+
- PostgreSQL 15+ (或Docker)
- Docker Desktop (可选)
### 安装
```bash
pip install contextos-sdk
```
或从源代码:
```bash
git clone https://github.com/AmanSagar0607/Context-OS.git
cd Context-OS
pip install -e packages/context-core
```
### 快速开始
```python
from context_ai import ContextAI, MemoryCreate, MemoryType, ImportanceLevel
client = ContextAI(api_key="your-api-key")
# 存储记忆
memory = client.memory.add(MemoryCreate(
content="用户偏好暗色模式和简洁的回复",
memory_type=MemoryType.SEMANTIC,
importance=ImportanceLevel.HIGH,
tags=["preference", "ui"],
))
# 搜索记忆
results = client.memory.search(query="用户有哪些UI偏好?")
for result in results:
print(f"{result.score:.2f} - {result.memory.content}")
```
---
## 架构
```
┌─────────────────────────────────────────────────────────────┐
│ 客户端 │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Python │ │ TypeScript│ │ CLI │ │ MCP │ │
│ │ SDK │ │ SDK │ │ │ │ Clients │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ API 服务器 (FastAPI) │
│ Memory Routes │ Search Routes │ Crawl Routes │ MCP │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ CONTEXT CORE (Python) │
│ Memory │ Retrieval │ Knowledge │ Crawl │ Search │ MCP │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ PostgreSQL + pgvector │
│ memories │ kg_entities │ users │ usage_records │ plans │
└─────────────────────────────────────────────────────────────┘
```
---
## API 参考
### 记忆
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| `POST` | `/api/v1/memory` | 存储记忆 |
| `GET` | `/api/v1/memory/:id` | 获取记忆 |
| `PUT` | `/api/v1/memory/:id` | 更新记忆 |
| `DELETE` | `/api/v1/memory/:id` | 删除记忆 |
| `POST` | `/api/v1/memory/search` | 语义搜索 |
| `POST` | `/api/v1/memory/context` | 获取上下文窗口 |
| `GET` | `/api/v1/memory` | 列表记忆 |
| `GET` | `/api/v1/memory/:id/related` | 相关记忆 |
### 搜索
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| `POST` | `/api/v1/search/web` | 网络搜索 |
| `POST` | `/api/v1/search/internal` | 内部混合搜索 |
### 爬取
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| `POST` | `/api/v1/crawl/scrape` | 抓取URL |
| `POST` | `/api/v1/crawl/crawl` | 爬取网站 |
| `POST` | `/api/v1/crawl/map` | 映射网站 |
| `POST` | `/api/v1/crawl/extract` | AI提取 |
### 知识
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| `POST` | `/api/v1/knowledge/entities` | 创建实体 |
| `GET` | `/api/v1/knowledge/entities/:id` | 获取实体 |
| `DELETE` | `/api/v1/knowledge/entities/:id` | 删除实体 |
| `POST` | `/api/v1/knowledge/relationships` | 创建关系 |
| `GET` | `/api/v1/knowledge/graph/:id` | 获取实体图谱 |
| `POST` | `/api/v1/knowledge/search` | 搜索实体 |
### MCP
| 方法 | 端点 | 描述 |
|--------|----------|-------------|
| `POST` | `/api/mcp` | MCP JSON-RPC |
| `POST` | `/api/mcp/sse` | MCP SSE传输 |
| `GET` | `/api/mcp/tools` | 列表MCP工具 |
| `GET` | `/api/mcp/health` | MCP健康检查 |
---
## 项目结构
```
Context-OS/
├── apps/
│ ├── server/ | MCP 工具 |
---
## 竞争分析
| 功能 | Mem0 | Firecrawl | Zep | Letta | LangGraph | CrewAI | **Context OS** |
|------------|------|-----------|-----|-------|-----------|--------|----------------|
| 记忆 | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ |
| 网络搜索 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ |
| 网络爬取 | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ |
| 知识图谱 | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ |
| MCP | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
| 自托管 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 开源 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
**没有其他人拥有所有五个功能在一个平台上。**
---
## 技术栈
| 组件 | 技术 |
|-----------|------------|
| API 服务器 | FastAPI(Python 3.13) |
| 数据库 | PostgreSQL 16 + pgvector |
| 嵌入 | sentence-transformers(默认),OpenAI,Cohere |
| 大型语言模型 | OpenRouter(GPT-4o-mini 默认) |
| 支付 | BaseUPI(零佣金UPI) |
| 前端 | Next.js 15,Tailwind CSS |
| 认证 | JWT + OAuth(Google,GitHub) |
| MCP | JSON-RPC 2.0,HTTP/SSE |
| Python SDK | httpx,pydantic |
| TypeScript SDK | fetch,TypeScript 5.6 |
| CLI | Click,Rich |
| 文档 | Docusaurus 3 |
---
## 部署
### Docker
```bash
docker compose up -d
```
### 环境变量
```env
# 数据库
DATABASE_URL=postgresql://postgres:password@localhost:5432/app-agent
# 大型语言模型
OPENROUTER_API_KEY=your-key
# 嵌入
EMBEDDING_MODEL=all-MiniLM-L6-v2
# 认证
AMAN_JWT_SECRET=your-secret
# 支付
BASEUPI_SECRET_KEY=your-key
```
---
## 测试
```bash
# 运行所有测试
cd packages/context-core
pytest tests/ -v
# 运行测试并生成覆盖率报告
pytest tests/ --cov=context_core
```
---
## 路线图
### 30 天 - 上线准备
- [x] Monorepo 结构
- [x] 统一记忆系统
- [x] 数据库迁移
- [x] 混合检索管道
- [x] Python + TypeScript SDK
- [x] CLI 工具
- [x] MCP 服务器重构(20种工具)
- [x] 文档
- [x] Docker部署
### 60 天 - 开发者采用
- LLM-based planner
- 记忆巩固
- HyDE 查询扩展
- 100 GitHub 明星
- 10 名外部用户
### 90 天 - 收入
- 云部署
- 基于使用的计费(Polar)
- 500 GitHub 明星
- 50 名外部用户
- 10 名付费客户
详见 [ROADMAP.md](ROADMAP.md) 获取详细计划。
---
# 赞助商
支持Context OS开发!赞助商将在README和项目文档中获得可见性。
<table>
<tr>
<td width="200">
<a href="https://github.com/sponsors/AmanSagar0607" target="_blank" title="成为白金赞助商">
<img src="https://img.shields.io/badge/Your_Logo_here-grey?style=for-the-badge&logo=github" alt="赞助商">
</a>
</td>
<td>
<a href="https://github.com/sponsors/AmanSagar0607" target="_blank"><b>您的公司名称</b></a><br/>
<i>白金赞助商将在README和文档中获得优先展示。</i>
</td>
</tr>
<tr>
<td width="200">
<a href="https://github.com/sponsors/AmanSagar0607" target="_blank" title="成为白金赞助商">
<img src="https://img.shields.io/badge/Your_Logo_here-grey?style=for-the-badge&logo=github" alt="赞助商">
</a>
</td>
<td>
<a href="https://github.com/sponsors/AmanSagar0607" target="_blank"><b>您的公司名称</b></a><br/>
<i>白金赞助商将在README和文档中获得优先展示。</i>
</td>
</tr>
</table>
<!-- sponsors -->
<!-- /sponsors -->
<i><sub>想在这里显示您的广告吗? <a href="https://github.com/sponsors/AmanSagar0607">成为赞助商</a> 并选择适合您的层级!</sub></i>
---
## 贡献
我们欢迎贡献!请在开始之前阅读我们的 [贡献指南](CONTRIBUTING.md)。
1. 分叉仓库
2. 创建功能分支 (`git checkout -b feature/amazing`)
3. 提交更改 (`git commit -m 'feat: add amazing feature'`)
4. 推送到分支 (`git push origin feature/amazing`)
5. 打开拉取请求
---
## 引用
如果您因研究目的使用了Context OS,请使用以下参考资料引用我们:
```text
@misc{contextos,
author = {Aman Sagar},
title = {Context OS},
year = {2026},
url = {https://github.com/AmanSagar0607/Context-OS},
note = {Context Infrastructure for AI Agents - Memory, Search, Crawl, Knowledge, MCP}
}
```
---
## 许可
本作品根据MIT许可协议授权。
---
## 构建者
<div align="center">
<table>
<tr>
<td align="center">
<a href="https://amansagar.in">
<img src="https://avatars.githubusercontent.com/u/AmanSagar0607" width="100" style="border-radius:50%" alt="Aman Sagar"/>
</a>
</td>
</tr>
<tr>
<td align="center">
<b>Aman Sagar</b><br/>
<sub>全栈开发者 & AI爱好者</sub>
</td>
</tr>
<tr>
<td align="center">
<a href="https://amansagar.in" target="_blank">
<img alt="网站" src="https://img.shields.io/badge/🌐-amansagar.in-blue?style=flat-square">
</a>
<a href="https://x.com/AmanSagar0607a" target="_blank">
<img alt="X (formerly Twitter)" src="https://img.shields.io/badge/𝕏-@AmanSagar0607a-black?style=flat-square&logo=x&logoColor=white">
</a>
<a href="https://discord.gg/YrSpR43UB" target="_blank">
<img alt="Discord" src="https://img.shields.io/badge/Discord-Join-5865F2?style=flat-square&logo=discord&logoColor=white">
</a>
<a href="https://github.com/AmanSagar0607" target="_blank">
<img alt="GitHub" src="https://img.shields.io/badge/GitHub-AmanSagar0607-181717?style=flat-square&logo=github">
</a>
<a href="https://linkedin.com/in/amansagar0607" target="_blank">
<img alt="LinkedIn" src="https://img.shields.io/badge/LinkedIn-amansagar0607-0A66C2?style=flat-square&logo=linkedin">
</a>
</td>
</tr>
</table>
</div>
---
## 致谢
为AI代理社区精心打造。
---
<div align="center">
<a href="https://github.com/sponsors/AmanSagar0607" target="_blank">
<img src="https://img.shields.io/badge/⭐_Star_this_repo-FF4500?style=for-the-badge&logo=github&logoColor=white" alt="Star this repo">
</a>
<br/><br/>
<sub>由 <a href="https://amansagar.in">Aman Sagar</a> 制作 | <a href="https://x.com/AmanSagar0607a">@AmanSagar0607a</a></sub>
</div>
MCP 配置
以下是此 MCP Server 的配置信息,可直接复制到 Cursor 或其他 MCP 客户端中使用。
mcp.json
连接信息
猜你喜欢
暂无推荐服务器