본문으로 건너뛰기
cccskills
무료GitHub에 공개

memory-optimization

Tune moflo's memory stack for speed, RAM, and index quality. Covers HNSW parameters (M, efConstruction, ef), vector quantization, batch operations, and common bottlenecks. Use when scaling past ~100k entries or when search latency regresses.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md4.9 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

MoFlo Memory Optimization

When the default moflo memory settings stop being enough — past ~100k entries, or when p95 search latency climbs — these are the levers.

HNSW Parameters

HNSW has three knobs. They trade build time, query time, memory, and recall.

import { HNSWIndex } from 'moflo/dist/src/cli/memory/index.js';

const index = new HNSWIndex({
  dimensions: 1536,        // must match your embedding model
  maxElements: 1_000_000,  // pre-allocated capacity
  M: 16,                   // graph connectivity (default 16)
  efConstruction: 200,     // build-time search width (default 200)
  metric: 'cosine',        // 'cosine' | 'l2' | 'ip'
});
KnobHigherLowerWhen to change
Mbetter recall, more RAM (~2×M pointers per point)less RAM, worse recallBump to 32–64 if recall@10 < 0.95; drop to 8 if memory-bound
efConstructionbetter index quality, slower buildfaster build, worse queries200–400 is sweet spot; only lower in test fixtures
ef (search-time, passed to search())better recall, slower queriesfaster queries, worse recallStart at 2×k, raise until recall plateaus

Rule of thumb: M and efConstruction are set once. ef is the runtime dial.

Quantization

moflo memory supports scalar quantization (Float32 → Int8) for a ~4× memory reduction with a ~1-2% recall hit. Turn it on when the index doesn't fit comfortably in RAM.

const index = new HNSWIndex({
  dimensions: 1536,
  maxElements: 5_000_000,
  quantization: {
    enabled: true,
    type: 'scalar',   // scalar (Int8) is the supported path
    rebuildThreshold: 10_000,
  },
});

Measure recall before/after on your own query distribution — public benchmarks don't predict your domain.

Batch Operations

Single-entry writes pay the HNSW insert cost per call. For bulk ingest, batch:

const entries: Array<[string, Float32Array]> = buildCorpus();

// Parallelise at the adapter level; don't await sequentially.
await Promise.all(
  entries.map(([id, vec]) => index.addPoint(id, vec))
);

// Or via MCP for moflo-native batch into .swarm/memory.db:
await mcp.memory_store(/* … */);  // upsert: true + Promise.all is fine

For >10k entries, prefer bin/build-embeddings.mjs / bin/index-all.mjs — they stream in batches with a progress bar and skip unchanged chunks via a hash file.

Caching

MofloDbAdapter has a built-in LRU cache (default 10k entries, 5-min TTL):

import { MofloDbAdapter } from 'moflo/dist/src/cli/memory/index.js';

const store = new MofloDbAdapter({
  cacheEnabled: true,
  cacheSize: 50_000,      // scale with working set, not total corpus
  cacheTtl: 10 * 60_000,  // 10 minutes
});

Cache hits on exact keys bypass HNSW entirely. If your workload is read-heavy and hits a narrow keyspace, this is the cheapest win.

Measuring

npx vitest bench src/cli/memory/benchmarks/vector-search.bench.ts

The bench prints linear vs HNSW times for 1k and 10k vectors. Run it before and after any parameter change — "it felt faster" is not a benchmark.

For production memory stats:

const stats = await mcp.memory_stats({});
// { entryCount, indexSize, cacheHitRate, avgSearchMs, … }

Common Bottlenecks

SymptomLikely causeFix
Cold-start of 5s on first searchHNSW loading from diskShare a single instance via beforeAll in tests; keep the adapter resident in long-running processes
Search latency climbs linearly with limitOver-fetching and re-ranking on the hot pathLower limit; raise threshold to prune
Inserts slow past ~100k entriesmaxElements too close to entry count → reallocationSet maxElements to 2× expected corpus
High RSS on a small corpusVector dimension mismatch with indexConfirm dimensions matches embedder output (OpenAI = 1536, local models vary)

Anti-Patterns

  • Don't rebuild the index on every test. Use a module-level singleton + beforeAll. HNSW cold-boot is ~5s.
  • Don't raise ef globally. Raise it on the specific queries that need recall. Default is fine for 90% of calls.
  • Don't quantize a small corpus. Below ~500k vectors the RAM saving doesn't justify the recall cost.
  • Don't measure in dev mode. The memory stack behaves differently under NODE_ENV=production; benches should match the target.

See Also

  • memory-patterns skill — API usage and namespace design
  • vector-search skill — RAG-specific patterns on top of the optimized index
  • src/cli/memory/benchmarks/ — runnable benches for every knob above

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

commune

무료

Turn a vague idea into a concrete, actionable spec through a short Socratic dialogue, then hand the result off to an existing moflo surface — a /flo ticket, a spell, or memory. Use BEFORE you have a defined unit of work, when the goal is still fuzzy.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

eric-cielo/moflo192026년 10월 18일 업데이트

Scaffold new spell step commands and connectors. Use when building new step commands for spells or extending the spell engine with new capabilities. Connectors are for new I/O transport types OR platforms requiring complex multi-step interaction (e.g., browser-based automation).

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

eric-cielo/moflo192026년 10월 18일 업데이트

distill

무료

Alias for /flo-simplify — see that skill's description.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

eric-cielo/moflo192026년 10월 18일 업데이트

divine

무료

Structured multi-hop web research with explicit confidence gating — plan the inquiry, search (WebSearch/WebFetch), score your own confidence, and keep digging until the answer is well-supported or a hop cap is hit, then emit a cited synthesis. Learns across sessions by storing each research case to memory and reusing prior strategies. Use when a question needs more than one search — comparisons, current-best-practice questions, anything where a single lookup leaves you unsure.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

eric-cielo/moflo192026년 10월 18일 업데이트

eldar

무료

Consult the Eldar — audit a project's moflo + Claude Code setup for portable, high-leverage gaps and guide remediation. Default mode is read-only audit with severity-ranked findings; --fix presents an interactive triage menu and walks the user through each chosen fix (healer, missing CLAUDE.md, sparse guidance, hook/MCP wiring, empty memory namespaces, stack→guidance gaps). Use when starting in a new project, when Claude feels lost or inefficient, when guidance/CLAUDE.md is sparse, or as a periodic health check.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

eric-cielo/moflo192026년 10월 18일 업데이트

flfl

무료

Run /fl on a ticket with moflo's three standing considerations loaded first — cross-platform (Rule

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

eric-cielo/moflo192026년 10월 18일 업데이트

eric-cielo의 스킬 모두 보기

이 스킬의 문제 신고