跳到正文
cccskills
免费在 GitHub 公开中文介绍

full-text-search

此技能指导你调整产品数据的全文检索,涵盖 PostgreSQL 与 Elasticsearch 检索路径、权限校验、文档映射、增量同步和重新索引;不涉及智能体的外部网页搜索。

原文查看原文说明

Use for product search: FtsSearchRepo, pg_search/pg_like/Elasticsearch, mapping migrations, projections, Outbox sync, reindexing and performance. Excludes agent web search.

lobehub/lobehub星标 83,506(GitHub 83,506 + cccskills 0)
集成工具DockerPostgreSQL

实测评分 未实测

查看安装方法

适用场景

  • 将产品数据加入搜索
  • 更换搜索服务提供方
  • 更新映射或搜索文档
  • 规划重新索引与同步
  • 检查权限和搜索性能

中文介绍

功能

此技能用于指导产品数据全文检索的设计和实现,数据包括智能体、消息、文件和知识库。它涵盖通过仓库接口处理搜索请求、划分 PostgreSQL 与 Elasticsearch 服务提供方的职责、维护搜索文档映射和投影,以及在结果中保留数据库权限检查。添加可搜索的数据类型时,还需要检查相关类型、文档结构、搜索逻辑、变更捕获、重新索引和持续同步。内容也涉及通过 Outbox 同步变更、迁移检查点、版本管理、监控和测试。

适用场景

添加产品数据作为搜索对象、切换搜索服务提供方或调整映射时,可以参考此技能。它也适用于规划从 PostgreSQL 迁移至 Elasticsearch 或重建索引,以及在改造搜索功能时维持结果权限和同步行为。

使用示例

  • “请整理将一种新数据类型加入全文检索的步骤。”
  • “请检查这次 Elasticsearch 映射调整和重新索引会带来什么影响。”
  • “请确认同步过程能否保留权限检查和搜索结果格式。”

注意事项

此技能针对产品内数据搜索,不包括智能体使用的外部网页搜索。可用的搜索服务提供方包括 pg_search、elasticsearch 和 pg_like。操作 Elasticsearch 需要相应配置和运行环境;原文以能够访问相关开发仓库、数据库及搜索服务为前提。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

文档检查

AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。

安全性发送数据、删除文件、执行命令等是否有说明
B部分不足资料涉及同步和搜索切换,虽说明切换条件,但仍包含运维操作。
安装难易度所需工具和 API 密钥是否少且有说明
B部分不足资料以 Elasticsearch 配置及仓库、数据库和搜索服务访问权限为前提,安装说明不完整。

不计入评分。 由 AI(OpenAI Codex)于 2026年10月26日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(2)

  • SKILL.md15.9 KB
  • references/mapping-migrations.md14.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Product Full-Text Search

This skill covers search over LobeHub-owned product data such as agents, topics, messages, files, knowledge bases, documents, chat groups, and memories. It does not cover the agent's external web search providers under apps/server/src/services/search/ or builtin web-browsing tools.

Architecture

Product reads follow one stable path:

router/service -> createFtsSearchRepo -> FtsSearchRepo -> selected backend -> existing result schema
  • apps/server/src/services/ftsSearch/ owns request-scoped provider selection, Elasticsearch configuration, its HTTP client, and backend telemetry. Routers and domain services must call createFtsSearchRepo; they must not construct providers themselves.
  • packages/database/src/repositories/ftsSearch/ owns the provider-neutral contract and the concrete PostgreSQL and Elasticsearch implementations. Keep public result shapes stable in FtsSearchRepo.
  • packages/types/src/ftsSearch.ts owns the shared searchable-entity list and search domain types.
  • packages/database/src/repositories/ftsSearchDocument/ owns Elasticsearch document schemas, mappings, queryable fields, and source-to-document projection.
  • packages/database/src/schemas/ftsSearchSyncOutbox.ts and packages/database/src/repositories/ftsSearchSyncOutbox/ own durable change capture, claims, retries, dead letters, leases, revision fences, and capture-definition validation.
  • scripts/elasticsearchReindex/ owns the resumable full-backfill command and its operational runtime. Shared database source queries and document construction remain in packages/database/src/repositories/ftsSearchDocument/. apps/server/src/services/ftsSearchSync/ and scripts/elasticsearchSync/ own continuous incremental draining.
  • packages/env/src/ftsSearch.ts owns generic Elasticsearch environment variables.

Provider and Permission Invariants

  • FTS_SEARCH_PROVIDER is a deployment-level provider selector with current values pg_search, elasticsearch, and pg_like. It is not a feature flag or a user rollout. Add another enum value only when its provider covers all entities in FTS_SEARCH_BACKEND_ENTITIES end to end, including mode: 'candidates' when the provider enables ftsSearchCandidateEnabled.
  • Provider errors, missing configuration, and unsupported candidate behavior must remain visible. Never silently retry through another provider. pg_like is an explicitly selected lightweight provider, not an implicit fallback: a missing extension or unreachable service must still fail.
  • packages/database/src/repositories/ftsSearch/postgres/ owns the query, permission, pagination, and hydration layer shared by PostgreSQL providers. pgSearch/ and pgLike/ own only their provider adapter, dialect, and provider-specific candidate behavior. Neither provider directory may import the other, so either provider can be retired without owning shared functionality.
  • Before selecting Elasticsearch, require coverage tests proving that it supports every entity in the provider-neutral backend contract. Do not add per-entity routing between providers.
  • Preserve userId, workspaceId, and caller-agent visibility throughout every provider. Candidate retrieval must not broaden the caller's scope.
  • Where Elasticsearch only supplies candidate IDs, PostgreSQL hydration and parent checks remain the authoritative permission boundary. Do not return raw Elasticsearch hits directly when the existing result path requires database authorization or hydration.
  • Provider implementations return the existing hydrated response types and ordering contract. Do not make routers understand provider-specific result shapes.

Changing a Searchable Entity

Scope for pg_like

pg_like primarily serves individual users with small datasets. Review it for correct matching, permissions, and usable result ordering at that scale. For richer search quality or larger datasets, recommend self-hosted Elasticsearch or Elastic Cloud. Do not add indexes or change the database schema as part of pg_like optimization. Keep repairs bounded; distinguish new implementation bugs from shared provider limitations and deliberate lightweight-search trade-offs. Do not infer a personal-user performance problem from large shared development datasets without representative measurements.

Entity changes

Treat an entity addition or projection change as one cross-layer change. Inspect and update every applicable item:

  1. FTS_SEARCH_DOCUMENT_ENTITIES and shared request/result types.
  2. Search document schema, mapping, text fields, filters, fixtures, and mapping parity tests.
  3. FtsSearchDocumentBuilder, including soft deletion and fanout from related source rows.
  4. PostgreSQL and Elasticsearch backend behavior, permission hydration, pagination, and ranking.
  5. Capture functions/triggers or fanout queries in captureInfrastructure.ts.
  6. Reindex checkpoints, Outbox draining, metrics, and self-host documentation.

Schema fields, mappings, builders, and fixed fixtures must agree. Current mapping fields plus explicit FTS_SEARCH_RETAINED_SOURCE_PROPERTIES must equal the current Zod fields, without overlap. Retained source properties keep older open indexes writable during field removals; keep the builder producing them until those indexes are closed. They must not appear in current query metadata. A field outside the document schema must not appear in a mapping or query field list.

Elasticsearch multi_match query length is bounded by a shared leaf-clause budget divided by the selected query-field count. Adding a field reduces that entity's safe query length, and changing a query analyzer to emit multiple terms per Unicode code point requires revisiting the budget and its field-count regression tests.

Capture, Reindex, and Sync

  • Regular database migrations own durable schema: the revision sequence, Outbox table and indexes, and schema-managed source indexes such as the Memory fanout GIN index.
  • Capture functions and triggers are installed only when an operator explicitly enables the Elasticsearch path. installCaptureInfrastructure() is transactional, definition-checked, idempotent for an exact installation, and fail-closed for partial or altered definitions.
  • Do not install capture for every PostgreSQL-only instance. Do not move a normal schema index into the runtime installer merely because it supports capture.
  • The Outbox coalesces by (entity, document_id). A newer capture resets retry/dead-letter state and allocates a new revision only after locking the conflicting row, preserving same-document commit order.
  • Sequence allocation is non-transactional. Use the existing write fences and committed revision boundary; never treat last_value alone as proof that all earlier Outbox rows are visible.
  • Claims use the precise lease timestamp as a fencing token. A stale worker must not acknowledge, fail, or release work reclaimed by another worker.
  • Permanent failures and exhausted retries become durable dead letters. A drain that creates or observes dead work must fail instead of continuing to publish a successful cutover signal.
  • Full backfill does not replace continuous sync. For the initial PostgreSQL-to-Elasticsearch cutover, keep the application on PostgreSQL until aliases are ready and the Outbox is empty and stable, then switch explicitly. Later mapping upgrades keep searches on the existing Elasticsearch alias until promotion.

The supported operator entrypoints below run from the OSS repository root. A wrapping repository may expose different package scripts; check its package.json before invoking these or the mapping migration commands linked below.

bun run db:install-fts-search-capture
bun run fts-search:reindex -- --status
bun run fts-search:reindex -- --apply --yes
bun run fts-search:sync -- --max-steps=8 --yes
bun run scripts/pgSearchCleanup/index.ts --status
bun run scripts/pgSearchCleanup/index.ts --apply --yes

Mapping Generations

Docker startup runs fts-search-elasticsearch-reindex.cjs --startup --yes after PostgreSQL migrations when the selected provider is Elasticsearch. It blocks serving until index migration and catch-up succeed. Persist the same checkpoint volume across application and migration containers; failed namespace locks still require explicit recovery. Continuous sync remains a separate worker. Hosted and manual workflows keep their explicit migration commands.

For mapping changes, generation operations, repeat/resume behavior, or deployment integration, read Mapping migration workflow. It routes to the public command guide and adds recovery, automation, and local Docker rehearsal rules.

  • Treat managed and Serverless Elasticsearch APIs as capability-constrained. Create operational metadata and control indexes with the smallest portable request, and add topology, storage, or index settings only after verifying that the target service supports them; settings accepted by a self-managed cluster may be rejected by a managed service.
  • Make idempotent Elasticsearch resource creation depend on the structured error type, such as resource_already_exists_exception, not a broad HTTP status range. Preserve any other creation failure and stop before follow-up reads or mutations instead of turning a rejected request into a misleading verification error.

Elasticsearch cannot change an existing field's type or index-time analyzer in place. The code declares the target and Elasticsearch records the live state, per entity:

  • FTS_SEARCH_INDEX_DEFINITIONS[entity].schemaVersion is the declared generation; the fingerprint is sha256 of the mapping plus the shared analysis. Add complete changed-entity definitions in a new ftsSearchDocument/migration/NNNN-meaningful-name/ batch, register it and update current pointers in migration/index.ts. Append expected fingerprints in __tests__/schemaSnapshots.json; preserve published batches and baselines. mappings.test.ts and migration/index.test.ts check current parity, history, version bumps and fingerprint changes. See migration/README.md for ownership. Shared analysis changes alter every entity fingerprint and classify as breaking for every entity; bump all affected versions and rebuild rather than using in-place upgrades.
  • Every physical index <alias>-v<n> or same-schema rebuild <alias>-v<n>-r<runId> carries _meta.{reindex_run_id, schema_version, schema_fingerprint}; the alias marks the live generation. A rebuild suffix is physical identity, not a schema-version bump. Indexes created before fingerprints existed may omit the fingerprint, but still need a valid run ID and schema version for sync readiness. _meta.schema_version wins over the -v<n> suffix because an in-place upgrade advances _meta without renaming the index.
  • The sync runtime accepts an alias that still serves an older generation (upgrade in progress) and refuses one that serves a newer generation or a different fingerprint of the declared version. It writes every change to all open <alias>-v* indexes plus the alias write index, pruning each document to the fields that index maps (every generation is dynamic: strict), so a new generation can be backfilled beside the live one; a bulk work item is acknowledged only when every existing generation accepted it (2xx or 409 conflict).
  • Canonical migration checkpoints remain keyed by (namespace, schemaVersion). Explicit current-version rebuild checkpoints add reindexRunId, so repeated v1 rebuilds never reuse a completed v1 cursor. --apply groups the requested entities by declared version, treats existing aliases as an upgrade (no --fresh-run), leaves existing aliases in place, and emits promotion_pending. A completed first install creates aliases. Promoting a newer generation requires a completed checkpoint, a fingerprint match when targeting the declared version, and an idle target-entity Outbox. Rollback to an older stamped generation can use its metadata without a retained checkpoint; --retire requires in_sync and only closes old generations; explicit --purge installs exact-index templates forbidding auto-creation before deleting eligible closed generations. --in-place requires mappingChange: additive, widens the live index with PUT _mapping, pins the checkpoint to that index, and backfills with external_gte so concurrent sync writes win.
  • Use --apply --rebuild-current --entity=<entity> --yes when projection or capture semantics changed without a physical mapping change and historical documents must be regenerated from PostgreSQL. Deploy runtime support first: sync must recognize -r<runId> generations before one is created. Resume with the reported --run-id=<uuid>. Promote with the exact --generation=<alias>-v<n>-r<uuid> because version-only selection is ambiguous. The old generation remains dual-written for rollback and becomes same-version retirement-eligible only after the promotion records which live run superseded it.
  • Checkpoints are local files, not Drizzle migration history. Preserve ES_REINDEX_STATE_DIR across invocations. Completed runs skip backfill; incomplete runs resume from saved cursors. Mutating CLI commands share a non-expiring Elasticsearch namespace lock, independent of checkpoint location. A failed command retains its lock when its outcome may be uncertain. Before --release-lock=<owner> --yes, stop the previous process and resolve pending requests; never assume age proves it stopped. The lock does not serialize old binaries or external operator actions.
  • Reconciliation is exact only on a first install; once an alias serves an entity, concurrent sync writes make a higher Elasticsearch count legitimate and only a shortfall fails.
  • scripts/elasticsearchReindex/runtime/generationService.ts owns classification (missing, unmanaged, in_sync, drift, upgrade_available, rollback_required), promotion, and retirement; keep them free of Cloud-specific policy.

Read docs/self-hosting/advanced/neon-pg-search-migration.mdx or its Chinese counterpart before changing the operational sequence. When database rollout or index cost affects the design, also use the db-migrations skill and measure the relevant operation on the actual Dev database before adding manual or deferred release steps.

Observability and Product Analytics

  • Server provider metrics and traces live in apps/server/src/services/ftsSearch/observability.ts. Keep labels bounded: entity, provider, operation, outcome, and coarse error type are acceptable; raw queries, user IDs, document IDs, and index contents are not.
  • User-perceived search behavior lives with the open-source Command Menu in src/features/CommandMenu/analytics.ts. Product analytics may cover end-to-end duration, rendered result counts, empty results, result clicks, and abandonment without a Cloud business slot.
  • Measurement or analytics failures must never alter the selected provider's result or error.
  • Backend metrics explain provider cost and latency; frontend events explain what the user actually experienced. Do not substitute one for the other.

Validation

  • Add or update focused tests beside every changed provider, mapping, builder, capture, sync, or analytics module.
  • Preserve boundary tests proving callers use FtsSearchRepo, providers cannot leak raw result shapes, and telemetry failures do not affect search behavior.
  • Test pagination after authorization drops candidates, delete/scope-change priority, concurrent Outbox claims and stale settlements, retry/dead-letter behavior, reindex resume identity, and capture-definition mismatch whenever those paths change.
  • Run bun run check <changed-files...> from the repository root. For migration or database-runtime changes, follow the db-migrations and testing skills and verify against the actual Dev database.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

acceptance

免费有简介

通过实际操作产品验证交付内容,记录用户可查看的证据,并发布验收报告。可检查已有验证计划或创建检查项,选择合适的操作界面,并使用 `lh` CLI 发布结果。

  • 实际检查更改后的产品行为
  • 收集截图或其他验证证据
  • 编写验证计划和报告
lobehub/lobehub8.4万2026年10月26日 更新

add-model-provider

免费有简介

本技能指导在 LobeHub 中接入 AI 模型提供商,涵盖运行时、模型信息、设置、品牌展示、文档和验收,并帮助判断新增模型是否需要新的提供商集成。

  • 为 LobeHub 接入新的 AI 模型提供商
  • 更新提供商设置说明或介绍
  • 判断添加模型是否需要新的提供商集成
lobehub/lobehub8.4万2026年10月26日 更新

add-setting-env

免费有简介

本技能指导如何用服务器端环境变量设置用户偏好默认值,涵盖变量校验、服务器配置、写入用户状态,以及更新 `.env.example` 和自托管文档。

  • 通过环境变量设置用户偏好默认值
  • 将设置接入服务器配置和用户状态
  • 更新环境变量示例及文档
lobehub/lobehub8.4万2026年10月26日 更新

agent-runtime-hooks

免费有简介

说明如何在智能体执行步骤、工具调用、人工审批、上下文压缩和子智能体调用时注册钩子。钩子可观察事件、模拟本地工具结果,也可通过 Webhook 按配置策略允许或拒绝工具调用。

  • 记录智能体步骤和错误
  • 测试时模拟工具结果
  • 通过 Webhook 允许或拒绝工具调用
lobehub/lobehub8.4万2026年10月26日 更新

agent-signal

免费有简介

此技能用于为智能体设计事件驱动的后台工作流,划分来源、信号、动作和策略的职责,并处理异步交接、去重、执行范围、完成记录与运行观测。

  • 添加事件触发的后台任务
  • 将工作移出对话请求
  • 防止动作重复执行
lobehub/lobehub8.4万2026年10月26日 更新

agent-testing-bot

免费有简介

本技能在 macOS 桌面聊天应用中测试机器人频道:打开应用、进入频道或联系人、发送消息、等待回复并截图。支持 Discord、Slack、Telegram、微信、飞书和 QQ;iMessage 使用 BlueBubbles 桥接。

  • 检查真实 Discord 频道中的机器人回复
  • 测试 Slack 或 Telegram 的对话流程
  • 记录 macOS 应用中的操作结果
lobehub/lobehub8.4万2026年10月26日 更新

查看 lobehub 的全部技能

报告此技能的问题