本文へ移動
cccskills
無料GitHub で公開

ai-vector-brain

Creates reusable vector-brain implementations: repo, docs, compliance. Use when building pgvector SQL, manifests, ingest scripts. Not for context design (dev-context-engineering).

インストール方法を見る

含まれるファイル(60)

  • SKILL.md23.8 KB
  • agents/openai.yaml319 B
  • assets/sql/001_schema.sql3.5 KB
  • assets/sql/002_indexes_hnsw.sql3.2 KB
  • assets/sql/003_hybrid_search_function.sql6.8 KB
  • assets/sql/004_ingest_ledger.sql1.1 KB
  • assets/sql/005_eval_tables.sql1005 B
  • assets/sql/006_rls_multitenant.sql2.6 KB
  • assets/sql/007_query_logs.sql2.9 KB
  • assets/sql/008_fts_hardening.sql6.9 KB
  • assets/sql/009_bm25_pg_search.sql4.3 KB
  • assets/sql/010_sparsevec.sql6.0 KB
  • assets/sql/011_quantize_rescore.sql6.5 KB
  • assets/sql/012_bitemporal_facts.sql14.5 KB
  • data/sources.json37.8 KB
  • examples/docs-hub-brain.manifest.json1.2 KB
  • examples/policy-brain.manifest.json1.3 KB
  • examples/repo-brain.manifest.json941 B
  • learnings.consolidated.md591 B
  • learnings.md819 B
  • references/agent-tool-contract.md4.2 KB
  • references/backend-selection-extended.md12.6 KB
  • references/backend-selection.md11.2 KB
  • references/bm25-when-ts_rank-isnt-enough.md13.8 KB
  • references/contextual-retrieval.md5.4 KB
  • references/corpus-playbooks.md9.7 KB
  • references/cost-calculation.md16.6 KB
  • references/deferred-extensions.md9.6 KB
  • references/dev-context-hub-vector-recipe.md8.0 KB
  • references/embedded-local-brain.md17.7 KB
  • references/embedding-drift-mitigation.md3.6 KB
  • references/embedding-runtime.md16.5 KB
  • references/eval-by-corpus-type.md2.6 KB
  • references/framework.md8.4 KB
  • references/graph-theory-at-scale.md16.8 KB
  • references/learned-sparse-splade-leg.md16.0 KB
  • references/lexical-vs-vector-vs-hybrid.md11.9 KB
  • references/postgres-fts-tuning.md10.3 KB
  • references/postgres-memory-verification.md4.7 KB
  • references/postgres-pgvector-default.md13.4 KB
  • references/production-runbook.md13.0 KB
  • references/quantization-and-rescore.md16.3 KB
  • references/reranking-recipe.md7.9 KB
  • references/s3-vectors-backend.md9.6 KB
  • scripts/build_eval_seed.py6.1 KB
  • scripts/build_vector_hub.sh3.9 KB
  • scripts/check_brain_manifest.py6.5 KB
  • scripts/chunk_corpus_files.py5.7 KB
  • scripts/chunk_markdown.py6.2 KB
  • scripts/embed_and_load.py12.7 KB
  • scripts/inventory_corpus.py2.4 KB
  • scripts/prepare_documents.py2.3 KB
  • scripts/retrieve.py6.5 KB
  • scripts/test_build_vector_hub.py3.8 KB
  • scripts/test_check_brain_manifest.py2.1 KB
  • scripts/test_chunkers_fail_closed.py1.0 KB
  • scripts/test_prepare_documents_metadata.py1.3 KB
  • scripts/test_sql_asset_contracts.py10.1 KB
  • scripts/test_verify_postgres_memory.py7.6 KB
  • scripts/verify_postgres_memory.py16.2 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

AI Vector Brain

Build a vector brain implementation. V1 default: Postgres + pgvector. Pick a corpus playbook.

For source code, first show a gain over ripgrep, tree-sitter, or code-graph retrieval (see Corpus Readiness Gate); pgvector fits docs and prose corpora.

Use this skill when the user asks to:

  • build a vector brain, RAG brain, LLM brain, repo brain, docs brain, or compliance brain
  • turn a repo, docs hub, policy corpus, guide set, or generated context artifacts into a repeatable retrieval layer
  • choose a vector-brain backend and produce a concrete implementation path
  • create SQL, manifests, ingestion scripts, eval seeds, or an agent retrieval tool contract

Boundary Contract

SkillOwnsDoes Not Own
ai-context-layerWhere context lives: memory vs retrieval vs tools, grounding, provenance, lifecycle, app context architecturePaste-ready SQL, vector DB schemas, embedding pipelines, ingest scripts
ai-ragRetrieval theory: chunking principles, hybrid fusion concepts, reranking concepts, eval theory, when retrieval is wrongOperational DDL, backend-specific SQL, concrete ingest scripts
ai-agentsAgent topology, tool use, planner/critic flows, agent vs workflow decisionsRetrieval backend implementation
ai-bot-builderBot UX, conversation flows, escalation, channel integration, KB use in a bot surfaceKB/vector-brain construction
ai-vector-brainHow to build: corpus inventory, manifests, DDL, ingest scripts, embeddings, hybrid search, eval seeds, backend recipesBroad RAG theory, app context strategy, agent topology, bot UX

Quick Reference

NeedStart Here
Decide vector vs relational vs graph (upstream choice)../software-database-design/references/storage-paradigm-selection.md
Build the default brainreferences/postgres-pgvector-default.md
Choose backend (matrix + decision flow)references/backend-selection.md
Per-backend deep dive (S3 Vectors, Turbopuffer, Pinecone Serverless, Bedrock KB, OpenSearch, Vertex, Azure, edge)references/backend-selection-extended.md
S3 Vectors cost, limits (per-index vector limit, region availability), direct API vs Bedrock KBreferences/s3-vectors-backend.md
Estimate cost (formulas, sizing, worked examples for hot vs object-backed vs managed)references/cost-calculation.md
Pick corpus recipereferences/corpus-playbooks.md
Define portable manifestreferences/framework.md
Expose brain to agentsreferences/agent-tool-contract.md
Choose eval gatesreferences/eval-by-corpus-type.md
Verify temporal facts and RLS on server PostgreSQLpostgres-memory-verification
Prove retrieval before ANN../ai-rag/scripts/exact_search_baseline.py + ../ai-rag/assets/eval/golden-retrieval-cases.jsonl
Compare backends fairly../ai-rag/references/backend-comparison-fixtures.md
Trace production retrieval../ai-rag/references/observability-tracing-contract.md
Debug quality drops../ai-rag/references/retrieval-debugging-runbook.md
Red-team retrieval security../ai-rag/references/security-red-team-cases.md
Lift retrieval with contextual summariesreferences/contextual-retrieval.md
Add cross-encoder rerankingreferences/reranking-recipe.md
Decide the retrieval leg (lexical vs vector vs hybrid vs plain SQL, per query)references/lexical-vs-vector-vs-hybrid.md
Add real BM25 when ts_rank's missing IDF/length-saturation fails evalsreferences/bm25-when-ts_rank-isnt-enough.md
Add a learned-sparse/SPLADE leg when dense misses rare-term precision and tsvector is too brittlereferences/learned-sparse-splade-leg.md
Ship a local/notebook/single-binary brain (no server)references/embedded-local-brain.md
Tune the lexical layer (tsvector weighting, exact tokens, multilingual, debug)references/postgres-fts-tuning.md
Turn a dev-context compiled hub or repo artifact set into a vector brainreferences/dev-context-hub-vector-recipe.md
Scale past ~10M vectors (HNSW tuning, DiskANN, quantization, sharding, graph-augmented retrieval)references/graph-theory-at-scale.md
Cut vector RAM/latency at the default tier (quantize + rescore)references/quantization-and-rescore.md
Run the embedder yourself (cost/residency bars a hosted API)references/embedding-runtime.md
Know what v1 doesn't ship and when to add itreferences/deferred-extensions.md
Ship to production (backups, RLS, observability, migration drills)references/production-runbook.md
Handle model drift and corpus drift without full re-embeddingreferences/embedding-drift-mitigation.md
Validate inventoryscripts/check_brain_manifest.py
Embed and load a corpusscripts/embed_and_load.py
Query the brain from the CLIscripts/retrieve.py

The bundled SQL assets default to 1024-dimensional embeddings. If the chosen embedding model uses a different output dimension, update every vector(N) and bit(N) occurrence in assets/sql/001_schema.sql, 003_hybrid_search_function.sql, 005_eval_tables.sql, and 011_quantize_rescore.sql before loading data.

V1 Workflow

  1. Inventory the corpus with scripts/inventory_corpus.py.
  2. Classify corpus type: repo/codebase, docs hub, or compliance/policy.
  3. Prepare normalized documents with scripts/prepare_documents.py.
  4. Chunk with stable anchors using scripts/chunk_corpus_files.py for mixed repo/context corpora or scripts/chunk_markdown.py for Markdown-only corpora.
  5. Choose retrieval unit: source chunk, parent-child chunk, or typed knowledge packet.
  6. Deduplicate canonical facts before embedding when the corpus has repeated versions, copied procedures, or near-duplicate docs.
  7. Create schema and indexes from assets/sql/.
  8. Embed and load retrieval units with scripts/embed_and_load.py (provider-agnostic; swap the Embedder class for a new backend).
  9. Optionally contextualize chunks at index time per contextual-retrieval.md when retrieval-failure rate is the bottleneck.
  10. Run hybrid retrieval with scripts/retrieve.py (lexical + vector + RRF; sets the required hnsw.iterative_scan session knob).
  11. Optionally rerank the top-N candidates with a cross-encoder per reranking-recipe.md before passing top-K to the generator.
  12. Seed evals with scripts/build_eval_seed.py, then hand-label expected evidence.
  13. Expose retrieval through the retrieve_context contract.
  14. Operate freshness with ingest ledgers, corpus versions, tombstones, query logs (assets/sql/007_query_logs.sql), and metric gates.
  15. Promote to production only after the selected backend runs its behavioral checks; for memory facts and RLS use server verification, and report missing prerequisites as not_run. Follow production-runbook.md (backups, RLS, SLOs, embedding migration drill).

Backend Stance

Postgres + pgvector is the V1 default because it is durable, scriptable, easy to inspect, and sufficient for most repo/docs/compliance brains. It is not the identity of the skill.

On-device iOS / Swift is out of scope here. When the retrieval target is an iPhone/iPad app running fully offline (sqlite-vec / NLEmbedding / Core Spotlight semantic index feeding an Apple Foundation Models or sentence-bank composer), this skill's pgvector + server scripts don't apply. Route to ../software-ios-ai-engine/SKILL.md for the on-device retrieval-stitch composer (Option C) and the shared { answer, grounding, followUps[], safetyBoundary } contract. Use this skill only for the upstream knowledge build (chunking, anchors, eval seeds) that ships into the bundle.

Dual-deployment pattern (server pgvector + on-device sqlite-vec mirror with shared content_hash so citations resolve identically across paths) plus full four-skill composition for natural conversational iOS surfaces is documented in composition-with-rag-context-vector.md — covers Path A (Foundation Models) and Path B (vector-DB-only) for three generic domain shapes (consumer reflection, regulated copilot, multi-turn emotional companion).

For non-iOS conversational surfaces (Android with Gemini Nano / AICore, web browser with Chrome window.ai or WebLLM, Telegram/Discord/WhatsApp/Slack bots via LangGraph + Mem0, voice surfaces), see conversational-surfaces-cross-platform.md — same composition skeleton, per-platform composer matrix (with-model and without-model paths), per-platform retrieval backend choice (ObjectBox Android, IndexedDB+WASM sqlite-vec web, server pgvector for bots).

Use backend-selection.md before choosing an alternative. The matrix covers four tiers:

  • SQL-native: pgvector, pgvectorscale, ParadeDB
  • Dedicated services: Qdrant, Weaviate, Milvus/Zilliz, Vespa, LanceDB, Chroma
  • Serverless / object-storage-backed (cost-driven): AWS S3 Vectors, Turbopuffer, Pinecone Serverless, Cloudflare Vectorize, Upstash Vector
  • Hyperscaler managed: AWS Bedrock Knowledge Bases, Azure AI Search, Vertex AI Vector Search, OpenAI File Search
  • Search-engine k-NN (lift-and-shift): Elasticsearch / OpenSearch, Redis Stack, MongoDB Atlas Vector

For per-backend deep dives and look-alike comparisons (S3 Vectors vs Turbopuffer vs Pinecone Serverless, Bedrock KB vs Vertex vs Azure vs OpenAI File Search), see backend-selection-extended.md.

Corpus Playbooks

V1 ships three playbooks:

  • Repo/codebase brain: exact path, symbol, module, ownership, structured profile, schema, and selected source retrieval. When scaffolding this brain, start from examples/repo-brain.manifest.json.
  • Docs hub brain: architecture, guides, generated docs, and cross-page navigation. When scaffolding this brain, start from examples/docs-hub-brain.manifest.json.
  • Compliance/policy brain: authority, effective-time, citation precision, and refusal-on-no-evidence. When scaffolding this brain, start from examples/policy-brain.manifest.json.

Support KB, note-vault, and generated graph + markdown playbooks are later increments unless the user explicitly asks for them.

Operational Defaults

  • Keep source truth separate from chunks and embeddings.
  • Store stable evidence IDs, source URIs, content hashes, freshness, ACL scope, and citation anchors.
  • Treat chunks as a default transport unit, not always the best knowledge unit. For policies, docs, support, and repeated business knowledge, consider typed claim or question-answer packets with source anchors, version state, and access scope.
  • Collapse near-duplicate units into canonical records before embedding when duplicate versions would crowd top-k results.
  • Use lexical + vector hybrid retrieval from the first production version.
  • Contextualize chunks at index time (not query time) when adopting contextual retrieval; embed the contextualized form, keep the original content for display and citation.
  • Rerank in the app layer with a cross-encoder, never inside the database; oversample candidates before reranking and size N by ai-rag ranking-pipeline-guide.md.
  • Add model_id to embeddings from day one; never overwrite embeddings in place during live migration.
  • Keep the manifest embedding_model dimension aligned with the SQL assets and CLI --dim.
  • Tombstone stale or deleted content; do not silently hard-delete normal corpus history.
  • Build a corpus-specific eval set before tuning chunk size, model, backend, or index parameters.
  • Treat retrieved chunks as untrusted external content until assembled into a grounded context bundle.

Corpus Readiness Gate

Do not embed until the corpus has stable source IDs, tenant or ACL scope, effective timestamps, deterministic extraction, duplicate handling, and a delete or tombstone path. Build a lexical or exact-search baseline and a gold set with evidence IDs first. The vector path may advance only when it improves the target retrieval slices and preserves authorization and deletion behavior. If the corpus contract is unstable, fix ingestion before tuning distance metrics or indexes.

Common Anti-Patterns

  • vector database first, source-of-truth model later

  • one chunking or retrieval-unit recipe for code, docs, and policies

  • treating arbitrary token windows as facts when the corpus needs atomic claims, obligations, decisions, or Q&A records

  • letting duplicate versions compete in embedding space instead of canonicalizing current/deprecated records

  • embeddings and raw source text in one undifferentiated table

  • pure vector search with no lexical leg for code, policy, or proper-noun-heavy docs

  • treating HNSW as infinite scale; quantizing without a rescore step; rebuilding PPR/Louvain inside the brain instead of reusing dev-context-code-graph / dev-context-multi-repo runners

  • contextualizing chunks at query time instead of index time (loses the precompute + prompt-caching cost win)

  • embedding the contextualized form but discarding the original chunk so citations can no longer point at the source text

  • reranking inside the database instead of app-layer; running rerank with N == K so there is nothing to rerank

  • mixing rerank scores across reranker models in the same eval cohort

  • no deletion, tombstone, or supersession path

  • semantic cache without corpus-version invalidation

  • tuning by vibes instead of labeled retrieval evals

  • citing chunks without stable source anchors

  • hiding operational SQL in theory skills where it drifts

  • no re-indexing line in the FinOps model — re-embedding a corpus is recurring, not one-time, and its cost scales with tokens, not with vector count. Use N × avg_tokens_per_chunk × $/1M-tokens (see references/cost-calculation.md Formula 4) with the embedding model's current per-token rate. Do not budget from a flat $-per-N-vectors figure. Budget it at architecture-design time, not after the first surprise invoice.

  • no embedding_model column on the vectors table — providers can silently upgrade models behind a stable API alias. Pin model name and version on every row (model_id, see Operational Defaults), and monitor cosine-similarity distribution between query embeddings and top-k results (rolling avg + stdev), alerting when the mean drifts more than 2σ from baseline. The pin-and-monitor mitigation holds whatever the size of a given provider-side change.

  • assuming "same model" means "same neighbourhood" forever — even with a frozen embedding model, corpus drift (new docs, expired docs, evolving terminology) reshapes the semantic landscape of the index over months. Schedule a quarterly drift check against a held-out labeled eval; trigger re-embed when recall@k falls below threshold. When full re-embed is too expensive, consider Drift-Adapter (see references/embedding-drift-mitigation.md) — the source paper reports recovering 95-99% of fresh-index recall at over 100x lower compute than a full re-embedding or dual-index migration.

  • picking a vector DB on raw k-NN throughput when the workload is filter-heavy — benchmark candidate backends with realistic filter cardinality and selectivity, not unfiltered top-k; metadata-filter performance varies widely by backend and payload-index design. Measure on your own workload rather than quoting a cross-vendor multiplier.

  • ingesting tens of millions of vectors because storage is cheap — query-corpus concentration (a small fraction of the corpus serving most queries) is a common pattern in production retrieval systems, but the skew is workload-dependent; read it from your own query logs. Premature scale inflates RAM, re-embed cost, and tail latency for queries that would have been fine on a much smaller index. Measure query-corpus concentration before sizing.

  • treating full-text search as identifier equality — the parser splits tokens and dictionaries normalize them; even simple lowercases. Keep exact identifiers in indexed key columns with explicit case semantics; use a tested simple+unaccent contribution for prose lookup. See references/postgres-fts-tuning.md.

  • unaccent() wrapped IMMUTABLE to fit a generated column — index goes silently stale when the unaccent ruleset changes. Use a text-search configuration instead.

  • assuming RRF makes lexical ranking irrelevant — RRF consumes rank positions, so normalization that changes the lexical order can change fusion. Evaluate lexical ordering separately; normalization cannot supply missing BM25 IDF.

  • assuming "it indexed" means "it ranked" — positions past 16383 are silently clamped (lexeme still matches; ts_rank_cd proximity degrades), and positions beyond 256 per lexeme are discarded; tsvector caps at 1 MB. Guard chunk size.

  • per-row language via a generated column — a generated column cannot pick its regconfig from a column; per-row language needs a trigger.

  • trigram GIN on full body text — pg_trgm GIN bloats on long text; index only the identifier/symbol column.

  • MTEB v1 and v2 scores are not directly comparable; confirm benchmark version when comparing embedding models.

Navigation

References

SQL Assets

Scripts

  • scripts/inventory_corpus.py
  • scripts/prepare_documents.py
  • scripts/chunk_corpus_files.py
  • scripts/chunk_markdown.py
  • scripts/embed_and_load.py
  • scripts/retrieve.py
  • scripts/build_eval_seed.py
  • scripts/check_brain_manifest.py
  • scripts/test_sql_asset_contracts.py — regression checks for SQL asset examples and reversible migration contracts
  • ../ai-rag/scripts/exact_search_baseline.py — backend-neutral exact-search proof before index tuning
  • ../ai-rag/scripts/hybrid_rrf_demo.py — portable hybrid/RRF smoke comparison for prediction files

Sources

Learnings Loop

When prior decisions or pitfalls are relevant, consult learnings.consolidated.md if present; use learnings.md only for needed history or as the available fallback. Otherwise skip both.

After applying it, if you encountered a pattern worth remembering, a mistake worth preventing, or a domain fact that surprised you, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Configures Claude Code hooks and Codex hooks.json/notify. Use when adding PreToolUse guards, Stop hooks, managed hooks, format-on-save, preflight, audits, or worktree/budget hooks.

日本語の概要は準備中です。原文の説明を表示しています。

vasilyu1983/AI-Agents-public932026年10月12日 更新

Configures and hardens Claude Code and Codex MCP servers. Use when connecting databases, APIs, SaaS, building servers, or serving a clearance-filtered knowledge base.

日本語の概要は準備中です。原文の説明を表示しています。

vasilyu1983/AI-Agents-public932026年10月12日 更新

Owns instruction files: AGENTS.md, CLAUDE.md, personal and repo rules. Use when writing, pruning, auditing them, sharing rules across Claude and Codex, or fixing ignored rules.

日本語の概要は準備中です。原文の説明を表示しています。

vasilyu1983/AI-Agents-public932026年10月12日 更新

Creates and audits agent skills: SKILL.md, references, scripts, runtime metadata. Use when writing, validating, or security-reviewing a skill, or fixing truncated skill listings.

日本語の概要は準備中です。原文の説明を表示しています。

vasilyu1983/AI-Agents-public932026年10月12日 更新

Adds per-skill learnings loops for dated patterns, mistakes, and domain facts. Use when wiring skill memory, consolidation, or drift audits.

日本語の概要は準備中です。原文の説明を表示しています。

vasilyu1983/AI-Agents-public932026年10月12日 更新

Chooses subagent, team, workflow, or debate and launches it on Claude Code or Codex. Use when delegating, running agent review boards, or installing shared agents.

日本語の概要は準備中です。原文の説明を表示しています。

vasilyu1983/AI-Agents-public932026年10月12日 更新

vasilyu1983 のスキルをすべて見る

このスキルの問題を報告する