关于 grepai-ollama-setup
该技能指导为 GrepAI 配置 Ollama 作为本地嵌入提供方,面向希望在本机进行代码向量化和搜索的用户,涵盖安装、模型选择与故障排查。
主要功能
- 01安装并启动 Ollama
- 02下载代码嵌入模型
- 03配置 GrepAI 的 Ollama 端点
- 04检查服务状态并排查连接问题
适用场景
- 01在本机配置 GrepAI 的嵌入提供方
- 02为多语言代码库选择嵌入模型
- 03排查 Ollama 未运行或模型缺失
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ yoanbernabeu/ grepai-skills --skill grepai-ollama-setup安装后在 Claude Code 中输入/grepai-ollama-setup确认已加载。
详细介绍
GrepAI 的 Ollama 设置
本技能介绍如何安装和配置 Ollama,将其作为 GrepAI 的本地嵌入提供方。Ollama 可实现 100% 私密的代码搜索,你的代码永远不会离开你的设备。
何时使用此技能
- 为 GrepAI 设置本地、私密的嵌入
- 首次安装 Ollama
- 选择并下载嵌入模型
- 排查 Ollama 连接问题
为什么选择 Ollama?
| 优势 | 说明 |
|---|---|
| 🔒 隐私 | 代码永远不会离开你的设备 |
| 💰 免费 | 无 API 费用 |
| ⚡ 快速 | 本地处理,无网络延迟 |
| 🔌 离线 | 无需互联网即可使用 |
安装
macOS(Homebrew)
# Install Ollama
brew install ollama
# Start the Ollama service
ollama serve
macOS(直接下载)
- 从 ollama.com 下载
- 打开
.dmg并拖动到 Applications - 从 Applications 启动 Ollama
Linux
# One-line installer
curl -fsSL https://ollama.com/install.sh | sh
# Start the service
ollama serve
Windows
- 从 ollama.com 下载安装程序
- 运行安装程序
- Ollama 会自动作为服务启动
下载嵌入模型
GrepAI 需要一个嵌入模型,将代码转换为向量。
推荐模型:nomic-embed-text
# Download the recommended model (768 dimensions)
ollama pull nomic-embed-text
规格:
- 维度:768
- 大小:约 274 MB
- 性能:非常适合代码搜索
- 语言:针对英语优化
替代模型
# Multilingual support (better for non-English code/comments)
ollama pull nomic-embed-text-v2-moe
# Larger, more accurate
ollama pull bge-m3
# Maximum quality
ollama pull mxbai-embed-large
| 模型 | 维度 | 大小 | 适用场景 |
|---|---|---|---|
nomic-embed-text | 768 | 274 MB | 通用代码搜索 |
nomic-embed-text-v2-moe | 768 | 500 MB | 多语言代码库 |
bge-m3 | 1024 | 1.2 GB | 大型代码库 |
mxbai-embed-large | 1024 | 670 MB | 最高准确度 |
验证安装
检查 Ollama 是否正在运行
# Check if Ollama server is responding
curl http://localhost:11434/api/tags
# Expected output: JSON with available models
列出已下载的模型
ollama list
# Output:
# NAME ID SIZE MODIFIED
# nomic-embed-text:latest abc123... 274 MB 2 hours ago
测试嵌入生成
# Quick test (should return embedding vector)
curl http://localhost:11434/api/embeddings -d '{
"model": "nomic-embed-text",
"prompt": "function hello() { return world; }"
}'
为 GrepAI 配置 Ollama
安装 Ollama 后,配置 GrepAI 使用它:
# .grepai/config.yaml
embedder:
provider: ollama
model: nomic-embed-text
endpoint: http://localhost:11434
运行 grepai init 时,这就是默认配置;因此,如果使用 nomic-embed-text,无需进行任何更改。
运行 Ollama
前台(开发)
# Run in current terminal (see logs)
ollama serve
后台(macOS/Linux)
# Using nohup
nohup ollama serve &
# Or as a systemd service (Linux)
sudo systemctl enable ollama
sudo systemctl start ollama
检查状态
# Check if running
pgrep -f ollama
# Or test the API
curl -s http://localhost:11434/api/tags | head -1
资源注意事项
内存用量
嵌入模型会加载到 RAM 中:
nomic-embed-text:约 500 MB RAMbge-m3:约 1.5 GB RAMmxbai-embed-large:约 1 GB RAM
CPU 与 GPU
Ollama 默认使用 CPU。如需更快地生成嵌入:
- macOS: 自动使用 Metal(Apple Silicon)
- Linux/Windows: 安装 CUDA 以支持 NVIDIA GPU
常见问题
❌ 问题: 连接 localhost:11434 时出现 connection refused
✅ 解决方案: 启动 Ollama:
ollama serve
❌ 问题: 找不到模型 ✅ 解决方案: 先拉取模型:
ollama pull nomic-embed-text
❌ 问题: 嵌入生成速度慢 ✅ 解决方案:
- 使用更小的模型
- 确认 Ollama 正在使用 GPU(检查
ollama ps) - 关闭其他占用大量内存的应用程序
❌ 问题: 内存不足 ✅ 解决方案: 使用更小的模型或增加系统 RAM
最佳实践
- 在 GrepAI 之前启动 Ollama: 确保
ollama serve正在运行 - 使用推荐模型:
nomic-embed-text的综合表现最佳 - 让 Ollama 保持运行: 将其作为后台服务运行
- 定期更新: 运行
ollama pull nomic-embed-text获取更新
输出格式
成功设置后:
✅ Ollama Setup Complete
Ollama Version: 0.1.x
Endpoint: http://localhost:11434
Model: nomic-embed-text (768 dimensions)
Status: Running
GrepAI is ready to use with local embeddings.
Your code will never leave your machine.
评论
支持 Markdown