mcpField
G
grepai-ollama-setup

grepai-ollama-setup

github.com/yoanbernabeu开发20800 次安装38 周前更新
代码仓库

关于 grepai-ollama-setup

该技能指导为 GrepAI 配置 Ollama 作为本地嵌入提供方,面向希望在本机进行代码向量化和搜索的用户,涵盖安装、模型选择与故障排查。

主要功能

  1. 01安装并启动 Ollama
  2. 02下载代码嵌入模型
  3. 03配置 GrepAI 的 Ollama 端点
  4. 04检查服务状态并排查连接问题

适用场景

  1. 01在本机配置 GrepAI 的嵌入提供方
  2. 02为多语言代码库选择嵌入模型
  3. 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(直接下载)
  1. 从 ollama.com 下载
  2. 打开 .dmg 并拖动到 Applications
  3. 从 Applications 启动 Ollama
Linux
# One-line installer
curl -fsSL https://ollama.com/install.sh | sh

# Start the service
ollama serve
Windows
  1. 从 ollama.com 下载安装程序
  2. 运行安装程序
  3. 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-text768274 MB通用代码搜索
nomic-embed-text-v2-moe768500 MB多语言代码库
bge-m310241.2 GB大型代码库
mxbai-embed-large1024670 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 RAM
  • bge-m3:约 1.5 GB RAM
  • mxbai-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

最佳实践

  1. 在 GrepAI 之前启动 Ollama: 确保 ollama serve 正在运行
  2. 使用推荐模型: nomic-embed-text 的综合表现最佳
  3. 让 Ollama 保持运行: 将其作为后台服务运行
  4. 定期更新: 运行 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