affaan-m/ECC · error · Error

memory search query is too long

Error message

memory search query is too long (maximum ${MAX_QUERY_CHARS} characters).

What it means

searchMemories trims the query and enforces a maximum query length of MAX_QUERY_CHARS before searching. Queries longer than the cap are rejected up front rather than processed, keeping search costs and regex/scan work bounded.

Solutions

  1. Shorten the query to the essential keywords within the character limit.
  2. Pre-process input in scripts: truncate or extract key terms before calling searchMemories.
  3. Check the library's MAX_QUERY_CHARS constant and enforce it in your own input UI.

Example fix

// before
searchMemories(entireDocument);
// after
const query = entireDocument.slice(0, MAX_QUERY_CHARS).trim();
searchMemories(query);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof query !== 'string' || query.trim().length > MAX_QUERY_CHARS) throw new Error('Search query too long; extract key terms first.');

Type guard

const isValidQuery = (q) => typeof q === 'string' && q.trim().length > 0 && q.trim().length <= MAX_QUERY_CHARS;

Try / catch

try {
  searchMemories(query);
} catch (err) {
  if (err.message.includes('query is too long')) {
    searchMemories(query.trim().slice(0, MAX_QUERY_CHARS));
  } else throw err;
}

Prevention

When it happens

Trigger: Calling searchMemories with a string whose trimmed length exceeds MAX_QUERY_CHARS — e.g. pasting an entire document as the search query.

Common situations: Using the memory search as a 'find similar' by feeding whole files; scripting that forwards unbounded user input or command-line blobs straight into the query parameter.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/80ff04ca385cda5b. Report an issue: GitHub.

Appendix: source

Thrown at scripts/lib/memory-vault.js:605

    if (index < 0) return best;
    return best < 0 ? index : Math.min(best, index);
  }, -1);
  const start = Math.max(0, (matchIndex < 0 ? 0 : matchIndex) - 60);
  const prefix = start > 0 ? '…' : '';
  const suffix = start + maxChars < normalized.length ? '…' : '';
  return `${prefix}${normalized.slice(start, start + maxChars)}${suffix}`;
}

function summarizeMemory(memory) {
  return Object.fromEntries(
    Object.entries(memory).filter(([key]) => key !== 'body')
  );
}

function searchMemories(query, options = {}) {
  const normalizedQuery = typeof query === 'string' ? query.trim() : '';
  if (normalizedQuery.length > MAX_QUERY_CHARS) {
    throw new Error(`memory search query is too long (maximum ${MAX_QUERY_CHARS} characters).`);
  }
  if (hasUnsafeControlCharacters(normalizedQuery)) {
    throw new Error('memory search query must not contain control characters.');
  }

  const kinds = options.kinds
    ? uniqueStrings(options.kinds, {
      label: 'kinds',
      limit: MEMORY_KINDS.length,
      validator: value => validateEnum(value, MEMORY_KINDS, 'memory kind'),
    })
    : null;
  const trust = options.trust
    ? validateEnum(options.trust, MEMORY_TRUST_STATES, 'memory trust')
    : null;
  const targetHarness = options.targetHarness
    ? validateSlug(options.targetHarness, 'target harness')
    : null;

View on GitHub (pinned to 8321021c54)