index-dir

command
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

index-dir — Directory indexing with files

Recursively walks a directory, reads .txt files, chunks them using BasicChunker, and indexes them into an in-memory store. After indexing, answers a given question and outputs sources.

Quick start

EMBEDDER_API_KEY=sk-... \
LLM_API_KEY=sk-... \
go run ./examples/index-dir/ -dir ./docs -query "How to configure authorization?"

Flags

Flag Default Description
-dir . Directory with .txt files (recursive)
-query Required. Question for RAG
-topk 5 Number of chunks for context
-chunk 500 Chunk size in runes
-overlap 60 Overlap between chunks in runes

Environment variables

Variable Default Description
EMBEDDER_API_KEY Required. API key for the embedder
EMBEDDER_BASE_URL https://api.openai.com Embedder API base URL
EMBEDDER_MODEL text-embedding-ada-002 Embedding model
LLM_API_KEY Required. API key for the LLM
LLM_BASE_URL https://api.openai.com LLM API base URL
LLM_MODEL gpt-4o-mini Language model

Example: indexing project documentation

# Save some .txt files to the docs/ folder
mkdir -p docs
echo "Authorization is done via a Bearer token in the Authorization header." > docs/auth.txt
echo "Configuration is stored in config.yaml in the project root." > docs/config.txt

EMBEDDER_API_KEY=sk-... LLM_API_KEY=sk-... \
go run ./examples/index-dir/ \
  -dir ./docs \
  -query "Where is the configuration stored?" \
  -topk 3 \
  -chunk 300

Example output

Found 2 files in "docs"
Indexing 2 documents...
Indexing complete.

Question: Where is the configuration stored?
────────────────────────────────────────────────────────────

Configuration is stored in config.yaml in the project root.

Sources:
  [1] docs/config.txt (score=0.944)
      Configuration is stored in config.yaml in the project root.

File format

Files with the .txt extension are read (case-insensitive). The file name becomes the document ID, the file path becomes the path metadata field. Empty files are skipped.

Documentation

Overview

Индексация директории с текстовыми файлами — пример использования draftRAG.

Рекурсивно обходит директорию, читает .txt файлы, чанкирует их и индексирует в in-memory store. После индексации отвечает на заданный вопрос.

Переменные окружения:

EMBEDDER_BASE_URL   — базовый URL embedder API (по умолчанию: https://api.openai.com)
EMBEDDER_API_KEY    — ключ API для embedder (обязательно)
EMBEDDER_MODEL      — модель embeddings (по умолчанию: text-embedding-ada-002)
LLM_BASE_URL        — базовый URL LLM API (по умолчанию: https://api.openai.com)
LLM_API_KEY         — ключ API для LLM (обязательно)
LLM_MODEL           — модель LLM (по умолчанию: gpt-4o-mini)

Флаги:

-dir    директория с .txt файлами (по умолчанию: .)
-query  вопрос для RAG (обязательно)
-topk   количество извлекаемых чанков (по умолчанию: 5)
-chunk  размер чанка в рунах (по умолчанию: 500)
-overlap перекрытие между чанками (по умолчанию: 60)

Запуск:

EMBEDDER_API_KEY=sk-... LLM_API_KEY=sk-... \
  go run ./examples/index-dir/ -dir ./docs -query "Как настроить авторизацию?"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL