fix: truncate oversized sections and clear DB on fresh ingest
Some checks failed
CI / PHP 8.3 (push) Failing after 2s
CI / PHP 8.4 (push) Failing after 2s

- Truncate content to 3800 chars before embedding (embeddinggemma has
  a 2048-token context, ~4K char limit). Eliminates all 73 Ollama 500
  errors from oversized plan sections.
- Clear brain_memories DB table when --fresh is used, keeping DB rows
  in sync with Qdrant vectors.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-03 16:02:11 +00:00
parent 331796c1da
commit 1ef8157822

View file

@ -133,11 +133,19 @@ class BrainIngestCommand extends Command
}
try {
$text = $section['heading']."\n\n".$section['content'];
// embeddinggemma has a 2048-token context (~4K chars).
// Truncate oversized sections to avoid Ollama 500 errors.
if (strlen($text) > 3800) {
$text = mb_substr($text, 0, 3800).'…';
}
$brain->remember([
'workspace_id' => $workspaceId,
'agent_id' => $agentId,
'type' => $type,
'content' => $section['heading']."\n\n".$section['content'],
'content' => $text,
'tags' => $tags,
'project' => $project,
'confidence' => $this->confidenceForSource($source),
@ -400,9 +408,13 @@ class BrainIngestCommand extends Command
$prop = $reflection->getProperty('collection');
$collection = $prop->getValue($brain);
// Clear Qdrant collection.
\Illuminate\Support\Facades\Http::withoutVerifying()
->timeout(10)
->delete("{$qdrantUrl}/collections/{$collection}");
// Truncate the DB table so rows stay in sync with Qdrant.
\Core\Mod\Agentic\Models\BrainMemory::query()->forceDelete();
}
private function expandHome(string $path): string