index • AI Agent SDK

index: Index a directory or file for knowledge retrieval.

index

Method

</div>

This is a method of the Knowledge class in the knowledge module.

Index a directory or file for knowledge retrieval.

Supports incremental indexing – only changed files are re-indexed.

Signature

python
def index(path: str, incremental: bool, force: bool, include_glob: list, exclude_glob: list, user_id: str, agent_id: str, run_id: str) -> Any

Parameters

ParamField str

Directory or file path to index

ParamField bool

If True, only index changed files (default: True)

ParamField bool

If True, re-index all files regardless of changes

ParamField list

List of glob patterns to include (e.g., [“.py”, “.md”])

ParamField list

List of glob patterns to exclude (e.g., [“.log”, “test_“])

ParamField str

Optional user ID for scoping

ParamField str

Optional agent ID for scoping

ParamField str

Optional run ID for scoping

Returns

ResponseField Any

IndexResult with indexing statistics

Uses

  • time_module.time
  • IndexResult
  • isfile
  • dirname
  • os.makedirs
  • FileTracker
  • tracker.load
  • IgnoreMatcher.from_directory
  • isdir
  • os.walk

Source

View on GitHub

praisonaiagents/knowledge/knowledge.py at line 859