OllamaPageIndexClient
in package
Ollama PageIndex Client
Handles two LLM calls per query for the PageIndex retrieval system:
- Tree construction — analyse document structure, return JSON tree
- Retrieval reasoning — given tree + query, return ranked node_ids
Uses Ollama chat endpoint at http://192.168.0.112:11434/api/chat Model: llama3.1:8b (configurable)
Tags
Table of Contents
Methods
- __construct() : mixed
- buildTree() : array<string|int, mixed>
- Build a hierarchical JSON tree from document content.
- fromSettings() : self
- Load config from ahg_settings table if available.
- getHealth() : array<string|int, mixed>
- Get health info including available models.
- isAvailable() : bool
- Check if Ollama is available and the model is loaded.
- retrieveNodes() : array<string|int, mixed>
- Given a tree and a query, reason about which nodes are relevant.
Methods
__construct()
public
__construct([array<string|int, mixed> $config = [] ]) : mixed
Parameters
- $config : array<string|int, mixed> = []
buildTree()
Build a hierarchical JSON tree from document content.
public
buildTree(string $documentText, string $documentType[, array<string|int, mixed> $metadata = [] ]) : array<string|int, mixed>
The LLM analyses the document structure and returns a table-of-contents style JSON tree with node IDs, titles, summaries, and child nodes.
Parameters
- $documentText : string
-
The full text content of the document
- $documentType : string
-
One of: ead, pdf, rico
- $metadata : array<string|int, mixed> = []
-
Optional metadata (title, identifier, level, dates)
Return values
array<string|int, mixed> —['success' => bool, 'tree' => array|null, 'model' => string, 'tokens_used' => int, 'generation_time_ms' => int, 'error' => string|null]
fromSettings()
Load config from ahg_settings table if available.
public
static fromSettings() : self
Return values
selfgetHealth()
Get health info including available models.
public
getHealth() : array<string|int, mixed>
Return values
array<string|int, mixed>isAvailable()
Check if Ollama is available and the model is loaded.
public
isAvailable() : bool
Return values
boolretrieveNodes()
Given a tree and a query, reason about which nodes are relevant.
public
retrieveNodes(array<string|int, mixed> $tree, string $query) : array<string|int, mixed>
Returns ranked node IDs with reasoning explanations.
Parameters
- $tree : array<string|int, mixed>
-
The hierarchical tree JSON (from buildTree)
- $query : string
-
The user's search query
Return values
array<string|int, mixed> —['success' => bool, 'matches' => array, 'reasoning' => string, 'model' => string, 'tokens_used' => int, 'generation_time_ms' => int, 'error' => string|null]