#!/usr/bin/env bash # Loads data/memory.md and data/claude-legacy-memory.md into the # memory-retrieval knowledgebase (POST /ingest). # # ponytail: one chunk per non-empty, non-heading line — both source files are # already one fact/paragraph per line (no hard-wrapping), so this needs no # real chunking logic. Re-run after editing either file; there's no dedup, # PGVector always inserts — clear the collection first if you need a clean # reload. set -euo pipefail cd "$(dirname "$0")/.." [ -f .env ] && set -a && . ./.env && set +a : "${MEMORY_RETRIEVAL_API_KEY:?Set MEMORY_RETRIEVAL_API_KEY in .env first}" MEMORY_RETRIEVAL_URL="${MEMORY_RETRIEVAL_URL:-http://localhost:8000}" ingest_file() { local file="$1" section="" local chunks="[]" while IFS= read -r line; do case "$line" in "#"*) section="${line#\# }"; section="${section#\#\# }"; continue ;; ""|"---") continue ;; esac chunks=$(jq --arg content "$line" --arg source "$file" --arg section "$section" \ '. += [{"content": $content, "metadata": {"source": $source, "section": $section}}]' <<<"$chunks") done < "$file" echo "Ingesting $(jq 'length' <<<"$chunks") chunks from $file..." curl -sf -X POST "${MEMORY_RETRIEVAL_URL}/ingest" \ -H "Authorization: Bearer ${MEMORY_RETRIEVAL_API_KEY}" \ -H "Content-Type: application/json" \ -d "{\"chunks\": ${chunks}}" > /dev/null } ingest_file data/memory.md ingest_file data/claude-legacy-memory.md echo "Done."