- Remove 7 redundant .env vars: DB_NAME, DB_USER, DB_HOST, DB_PORT, MEMORY_DB_NAME, MEMORY_DB_USER, MEMORY_DB_URL — all now derived from AGENT_NAME by config.ts and common.sh - Fix DB_HOST in common.sh pointing to .2 (controlplane) instead of .3 (db) - common.sh: normalise AGENT_NAME → Postgres identifier, same algorithm as db-identifiers.ts; embed config now reads from .env instead of overriding with stale OpenRouter values - embed.sh: drop OPENROUTER_API_KEY requirement; use EMBED_BASE_URL + EMBED_API_KEY (empty = local llama-server, no auth needed) - memory-hydrate-pg.sh, memory-lifecycle.ts: replace ai_brain/clawdie_brain literals with live DB_NAME / MEMORY_DB_NAME values Bump to 0.9.1. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --- Build: pass | Tests: pass — Tests 431 passed (431)
45 lines
1.4 KiB
Bash
Executable file
45 lines
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# embed.sh — Generate an embedding vector from text via the configured embedding endpoint.
|
|
#
|
|
# Defaults to local llama-server (EMBED_BASE_URL in .env).
|
|
# Set EMBED_API_KEY in .env for remote providers that require auth.
|
|
#
|
|
# Usage:
|
|
# ./embed.sh "text to embed"
|
|
# echo "text to embed" | ./embed.sh -
|
|
#
|
|
# Output: JSON array of floats (the embedding vector)
|
|
|
|
. "$(dirname "$0")/common.sh"
|
|
|
|
# Read input
|
|
if [ "${1:-}" = "-" ]; then
|
|
INPUT_TEXT=$(cat)
|
|
elif [ -n "${1:-}" ]; then
|
|
INPUT_TEXT="$1"
|
|
else
|
|
echo "Usage: embed.sh <text> | embed.sh -" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Escape for JSON
|
|
JSON_INPUT=$(python3 -c "import json,sys; print(json.dumps(sys.argv[1]))" "$INPUT_TEXT")
|
|
|
|
# Call embedding API (OpenAI-compatible: local llama-server or remote)
|
|
RESPONSE=$(curl -s -X POST "$EMBED_API_URL" \
|
|
-H "Authorization: Bearer ${EMBED_API_KEY:-}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"model\": \"$EMBED_MODEL\", \"input\": $JSON_INPUT, \"dimensions\": $EMBED_DIMENSIONS}")
|
|
|
|
# Extract embedding, error if missing
|
|
python3 -c "
|
|
import json, sys
|
|
r = json.loads(sys.argv[1])
|
|
if 'error' in r:
|
|
print(f'API error: {r[\"error\"]}', file=sys.stderr)
|
|
sys.exit(1)
|
|
if 'data' not in r or len(r['data']) == 0:
|
|
print(f'Unexpected response: {json.dumps(r)[:200]}', file=sys.stderr)
|
|
sys.exit(1)
|
|
print(json.dumps(r['data'][0]['embedding']))
|
|
" "$RESPONSE"
|