grepai-init

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GrepAI Init

GrepAI 初始化

This skill covers the
grepai init
command and project initialization.
本技能介绍
grepai init
命令及项目初始化流程。

When to Use This Skill

何时使用本技能

  • Setting up GrepAI in a new project
  • Understanding what
    grepai init
    creates
  • Customizing initial configuration
  • Troubleshooting initialization issues
  • 在新项目中设置GrepAI
  • 了解
    grepai init
    会创建哪些内容
  • 自定义初始配置
  • 排查初始化问题

Basic Usage

基本用法

bash
cd /path/to/your/project
grepai init
bash
cd /path/to/your/project
grepai init

What Init Creates

初始化会创建的内容

Running
grepai init
creates the
.grepai/
directory with:
.grepai/
├── config.yaml    # Configuration file
├── index.gob      # Vector index (created by watch)
└── symbols.gob    # Symbol index for trace (created by watch)
运行
grepai init
会创建
.grepai/
目录,包含以下文件:
.grepai/
├── config.yaml    # 配置文件
├── index.gob      # 向量索引(由watch命令创建)
└── symbols.gob    # 用于追踪的符号索引(由watch命令创建)

Default Configuration

默认配置

The generated
config.yaml
:
yaml
version: 1

embedder:
  provider: ollama
  model: nomic-embed-text
  endpoint: http://localhost:11434

store:
  backend: gob

chunking:
  size: 512
  overlap: 50

watch:
  debounce_ms: 500

trace:
  mode: fast
  enabled_languages:
    - .go
    - .js
    - .ts
    - .jsx
    - .tsx
    - .py
    - .php
    - .c
    - .h
    - .cpp
    - .hpp
    - .cc
    - .cxx
    - .rs
    - .zig
    - .cs
    - .pas
    - .dpr

ignore:
  - .git
  - .grepai
  - node_modules
  - vendor
  - target
  - __pycache__
  - dist
  - build
生成的
config.yaml
内容如下:
yaml
version: 1

embedder:
  provider: ollama
  model: nomic-embed-text
  endpoint: http://localhost:11434

store:
  backend: gob

chunking:
  size: 512
  overlap: 50

watch:
  debounce_ms: 500

trace:
  mode: fast
  enabled_languages:
    - .go
    - .js
    - .ts
    - .jsx
    - .tsx
    - .py
    - .php
    - .c
    - .h
    - .cpp
    - .hpp
    - .cc
    - .cxx
    - .rs
    - .zig
    - .cs
    - .pas
    - .dpr

ignore:
  - .git
  - .grepai
  - node_modules
  - vendor
  - target
  - __pycache__
  - dist
  - build

Understanding Default Settings

理解默认设置

Embedder Settings

嵌入模型设置

SettingDefaultPurpose
provider
ollama
Local embedding generation
model
nomic-embed-text
768-dimension model
endpoint
http://localhost:11434
Ollama API URL
设置项默认值用途
provider
ollama
本地嵌入模型生成
model
nomic-embed-text
768维度模型
endpoint
http://localhost:11434
Ollama API地址

Store Settings

存储设置

SettingDefaultPurpose
backend
gob
Local file storage
设置项默认值用途
backend
gob
本地文件存储

Chunking Settings

分块设置

SettingDefaultPurpose
size
512
Tokens per chunk
overlap
50
Overlap for context
设置项默认值用途
size
512
每个分块的Token数量
overlap
50
分块间的重叠长度(用于上下文关联)

Watch Settings

监听设置

SettingDefaultPurpose
debounce_ms
500
Wait time before re-indexing
设置项默认值用途
debounce_ms
500
重新索引前的等待时间

Ignore Patterns

忽略规则

Default patterns exclude:
  • Version control:
    .git
  • GrepAI data:
    .grepai
  • Dependencies:
    node_modules
    ,
    vendor
  • Build outputs:
    target
    ,
    dist
    ,
    build
  • Cache:
    __pycache__
默认忽略以下内容:
  • 版本控制目录:
    .git
  • GrepAI数据目录:
    .grepai
  • 依赖目录:
    node_modules
    ,
    vendor
  • 构建输出目录:
    target
    ,
    dist
    ,
    build
  • 缓存目录:
    __pycache__

Customizing After Init

初始化后的自定义配置

Edit
.grepai/config.yaml
to customize:
编辑
.grepai/config.yaml
进行自定义:

Change Embedding Provider

更换嵌入模型提供商

yaml
embedder:
  provider: openai
  model: text-embedding-3-small
  api_key: ${OPENAI_API_KEY}
yaml
embedder:
  provider: openai
  model: text-embedding-3-small
  api_key: ${OPENAI_API_KEY}

Change Storage Backend

更换存储后端

yaml
store:
  backend: postgres
  postgres:
    dsn: postgres://user:pass@localhost:5432/grepai
yaml
store:
  backend: postgres
  postgres:
    dsn: postgres://user:pass@localhost:5432/grepai

Add Custom Ignore Patterns

添加自定义忽略规则

yaml
ignore:
  - .git
  - .grepai
  - node_modules
  - "*.min.js"
  - "*.bundle.js"
  - coverage/
  - .nyc_output/
yaml
ignore:
  - .git
  - .grepai
  - node_modules
  - "*.min.js"
  - "*.bundle.js"
  - coverage/
  - .nyc_output/

Init in Monorepos

单体仓库(Monorepo)中的初始化

For monorepos, init at the root:
bash
cd /path/to/monorepo
grepai init
Or use workspaces for separate indices:
bash
grepai workspace create my-workspace
grepai workspace add my-workspace /path/to/project1
grepai workspace add my-workspace /path/to/project2
对于单体仓库,在根目录执行初始化:
bash
cd /path/to/monorepo
grepai init
或者使用工作区来创建独立的索引:
bash
grepai workspace create my-workspace
grepai workspace add my-workspace /path/to/project1
grepai workspace add my-workspace /path/to/project2

Re-Initialization

重新初始化

If you need to reset:
bash
undefined
如果你需要重置配置:
bash
undefined

Remove existing config

删除现有配置

rm -rf .grepai
rm -rf .grepai

Re-initialize

重新初始化

grepai init

**Warning:** This deletes your index. You'll need to re-run `grepai watch`.
grepai init

**警告:** 此操作会删除你的索引。你需要重新运行`grepai watch`来重建索引。

Verifying Initialization

验证初始化结果

After init, verify with:
bash
undefined
初始化完成后,通过以下命令验证:
bash
undefined

Check config exists

检查配置文件是否存在

cat .grepai/config.yaml
cat .grepai/config.yaml

Check status (will show no index yet)

检查状态(此时会显示尚未创建索引)

grepai status
undefined
grepai status
undefined

Common Issues

常见问题

Problem:
.grepai
already exists ✅ Solution: Delete it first or edit existing config:
bash
rm -rf .grepai && grepai init
Problem: Config created but Ollama not running ✅ Solution: Start Ollama before running
grepai watch
:
bash
ollama serve
Problem: Wrong directory initialized ✅ Solution: Remove
.grepai
and init in correct directory
问题:
.grepai
目录已存在 ✅ 解决方案: 先删除该目录或编辑现有配置:
bash
rm -rf .grepai && grepai init
问题: 配置文件已创建,但Ollama未运行 ✅ 解决方案: 在运行
grepai watch
前启动Ollama:
bash
ollama serve
问题: 在错误的目录中执行了初始化 ✅ 解决方案: 删除
.grepai
目录并在正确的目录中重新初始化

Best Practices

最佳实践

  1. Init at project root: Where your main code lives
  2. Add
    .grepai/
    to
    .gitignore
    :
    Index is machine-specific
  3. Customize ignore patterns: Exclude generated/vendored code
  4. Review config after init: Adjust for your stack
  1. 在项目根目录初始化: 即你的主代码所在目录
  2. .grepai/
    添加到
    .gitignore
    索引文件是机器特定的,无需提交到版本控制
  3. 自定义忽略规则: 排除生成的代码或第三方依赖代码
  4. 初始化后检查配置: 根据你的技术栈调整配置

Example .gitignore Addition

.gitignore 添加示例

gitignore
undefined
gitignore
undefined

GrepAI

GrepAI

.grepai/
undefined
.grepai/
undefined

Output Format

输出格式

After successful initialization:
✅ GrepAI Initialized

   Config: .grepai/config.yaml

   Default settings:
   - Embedder: Ollama (nomic-embed-text)
   - Storage: GOB (local file)
   - Chunking: 512 tokens, 50 overlap

   Next steps:
   1. Ensure Ollama is running: ollama serve
   2. Start indexing: grepai watch
初始化成功后的输出如下:
✅ GrepAI Initialized

   Config: .grepai/config.yaml

   Default settings:
   - Embedder: Ollama (nomic-embed-text)
   - Storage: GOB (local file)
   - Chunking: 512 tokens, 50 overlap

   Next steps:
   1. Ensure Ollama is running: ollama serve
   2. Start indexing: grepai watch