WeKnora/internal/application/repository
ochan.kwon 40b74e2efa feat(retriever): activate OpenSearch k-NN driver (PR 3 of 3)
Phase 3 (#1440) gate flip. PR 1 (#1445) + PR 2a (#1481) + PR 2b (#1482)
laid the type prep + driver skeleton + read/write paths as gated dead
code; this PR wires every activation surface so opensearch becomes a
registerable VectorStore engine.

Activation wiring
- internal/types: validEngineTypes / GetVectorStoreTypes (with HNSW
  bounds + knn_engine enum + Immutable hints) / retrieverEngineMapping /
  buildEnvStoreForDriver — every gated surface now recognises
  "opensearch". IndexConfig grows four omitempty HNSW fields (HNSWM /
  HNSWEFConstruction / HNSWEFSearch / KNNEngine), keeping other engines'
  serialised config byte-identical.
- internal/container: createOpenSearchEngine + the switch case in
  createEngineServiceFromStore; the RETRIEVE_DRIVER=opensearch env path
  in initRetrieveEngineRegistry; NewEngineFactory now closes over the
  AuditLogService (the EngineFactory type itself is unchanged).
- internal/application/service/vectorstore_healthcheck.go: a
  testOpenSearchConnection case so CreateStore's connectivity probe
  accepts opensearch instead of returning 400.
- internal/application/repository/retriever/opensearch/transport.go:
  NewOpenSearchClient is exported so the factory and env path can build
  the TLS-hardened client; healthcheck.go reuses the unexported
  probeVersion / probeKNNPlugin for the service-layer probe.

Service-layer validation
- validateOpenSearchIndexConfig validates the HNSW caps (m 2-100,
  ef_construction 2-4096, ef_search 1-10000, knn_engine ∈ lucene|faiss).
  Shards/replicas continue to be enforced by the flat ValidateIndexConfig.
  Create-only: UpdateStore mutates the name only.
- validateConnectionConfig requires addr for opensearch.

Sync implementations (stubs.go shrinks)
- CopyIndices (copy.go) mirrors the Elasticsearch / Qdrant pattern —
  search → BatchSave with the source_id remap for generated questions —
  so dim/keyword routing and the source_id contract come from BatchSave
  for free. embeddingMap is keyed by the *target* SourceID because
  OpenSearch's BatchSave looks up embeddings by SourceID
  (lookupEmbedding), not by chunk_id (the ES driver's convention).
  Pagination is from/size; copies larger than max_result_window
  (default 10000) need the scroll-based async path that lands later.
- BatchUpdateChunkEnabledStatus / BatchUpdateChunkTagID (bulk_update.go)
  group the input by target value and issue one _update_by_query per
  group over the cross-dim <base>_* pattern. Caller values flow through
  bound script params only — never string-interpolated into the Painless
  source — closing the script-injection surface.
- inspectByQueryResponse (byquery.go) mirrors inspectBulkResponse: the
  full failure reason goes to the debug log only; the returned error
  carries the bounded id + type.
- UpdateByQueryParams.Refresh is *bool in opensearch-go v4.6.0 (the same
  shape as DeleteByQuery's quirk), so refresh=wait_for is not
  expressible; we use refresh=true.

Driver-owned audit (DIP)
- A new opensearch.AuditSink interface (with nopSink + WithAuditSink
  functional option) lets the driver emit opensearch.index_created and
  opensearch.reindex_executed events without importing any service
  package — the service layer implements the interface. NewRepository
  takes opts, so existing 4-arg test call sites keep compiling unchanged.
- internal/container/audit_sink.go bridges AuditSink to AuditLogService.
  When the context carries no tenant (the env-path registration ctx
  during boot, for example) the adapter skips the emit with a warning
  rather than silently writing tenant_id=0, which would collide with the
  system-scope sentinel.

Frontend + polish
- FieldSchema (frontend/src/api/vector-store.ts) gains min/max/enum/
  immutable. VectorStoreSettings.vue is now schema-driven: a closed
  `enum` renders a t-select; number inputs use the schema's `:min`/`:max`
  and fall back to the legacy replica-vs-shard heuristic only when the
  schema does not pin them; a danger-coloured warning fires when
  insecure_skip_verify is toggled on (the switch and warning are wrapped
  in a vertical stack so the warning sits on its own row below the switch).
- i18n: labels for hnsw_m / hnsw_ef_construction / hnsw_ef_search /
  knn_engine / insecure_skip_verify plus the warning copy in en-US,
  ko-KR, zh-CN, ru-RU.
- docker-compose.dev.yml: an opensearch profile (single-node 3.3.2 with
  security plugin disabled for dev only). OpenSearch Dashboards lives in a
  separate, opt-in opensearch-ui profile so the heavy UI container is not
  forced up alongside the cluster (the driver e2e is fully curl-verifiable
  against :9200). The new docs/dev/opensearch-integration-test.md covers the
  end-to-end exercise and the single-node guidance (set replicas=0 to keep
  the cluster Green).

Gating-guard tests flipped
- The "OpenSearch is NOT in validEngineTypes / mapping / types list /
  env builder / stubs" guard tests from PR 1 / PR 2 are replaced by
  their positive counterparts in this PR. The test suite was the
  activation checklist; the activation flip is its diff.

Backward compatibility
- Additive everywhere. IndexConfig's new HNSW fields are omitempty so
  other engines' serialised config is byte-identical. Existing
  Elasticsearch / Qdrant / Milvus / Weaviate / Doris / TencentVectorDB
  stores are untouched. No migrations.

Test plan
- go build ./... clean
- go vet ./... clean
- gofmt -l clean on touched files
- go test ./... — only TestOssEnsureBucket_CreateFails (Aliyun OSS
  endpoint), the docreader gRPC tests, and the doris SQL-shape tests
  fail; all three are pre-existing on upstream/main and untouched by
  this PR.
- New tests across internal/types, opensearch, service and container —
  including a full end-to-end env-path test that exercises
  initRetrieveEngineRegistry with RETRIEVE_DRIVER=opensearch against an
  httptest cluster.
2026-05-29 16:32:27 +08:00
..
memory/neo4j fix: revert to neo4j v6 and workaround Go 1.24 Windows compiler bug with -p=1 2026-04-11 22:08:02 +08:00
retriever feat(retriever): activate OpenSearch k-NN driver (PR 3 of 3) 2026-05-29 16:32:27 +08:00
agent_share.go feat(rbac): lift org membership from per-user to per-tenant (Plan 3, #1303) 2026-05-18 17:28:58 +08:00
audit_log.go feat(rbac): daily retention sweep for audit_logs (default 90 days) 2026-05-18 17:28:58 +08:00
chunk.go fix(faq): correct PostgreSQL cast precedence in FAQ search 2026-05-12 16:42:21 +08:00
chunk_sqlite_test.go fix: SQLite/Lite mode compatibility for FAQ import and chunk operations 2026-04-15 20:37:10 +08:00
custom_agent.go refactor: 调整智能体配置,增强智能体选择与状态管理 2025-12-26 21:31:02 +08:00
datasource_repo.go refactor(datasource): remove WeCom document integration and related components 2026-03-30 20:46:07 +08:00
kbshare.go feat(rbac): lift org membership from per-user to per-tenant (Plan 3, #1303) 2026-05-18 17:28:58 +08:00
knowledge.go feat: add knowledge parse cancellation with finalizing post-process state 2026-05-28 20:16:02 +08:00
knowledge_span_repo.go feat: implement CancelOpenSpansByName method and related tests 2026-05-28 20:16:02 +08:00
knowledge_span_repo_test.go feat: implement CancelOpenSpansByName method and related tests 2026-05-28 20:16:02 +08:00
knowledgebase.go feat(knowledge-base): implement per-user pinning for knowledge bases 2026-05-18 17:28:58 +08:00
knowledgebase_sqlite_test.go feat(rbac): add tenant_members schema and auth wiring (PR 1 of 3, #1303) 2026-05-18 17:28:58 +08:00
mcp_service.go feat: add built-in MCP service support 2026-03-05 21:57:01 +08:00
mcp_tool_approval_repository.go fix(agent): 加固 MCP 工具人审批的跨实例与并发语义 2026-05-10 22:57:12 +08:00
message.go feat(datasource): implement data source management functionality 2026-03-30 20:46:07 +08:00
model.go fix(repository): correct query syntax to get correctly built-in models 2026-05-21 16:11:22 +08:00
organization.go feat(rbac): lift org membership from per-user to per-tenant (Plan 3, #1303) 2026-05-18 17:28:58 +08:00
session.go feat(session): persist last request state for UI restoration 2026-05-18 22:28:00 +08:00
session_test.go fix(session): scope session access by user 2026-05-14 15:56:43 +08:00
system_setting.go feat(system): consolidate system admin and settings into one Settings panel 2026-05-26 21:13:56 +08:00
tag.go fix(knowledgeBase): improve tag loading logic and ensure consistent behavior 2026-05-29 15:42:44 +08:00
task_queue.go perf(wiki-ingest): scale to 4w-doc KBs + generic task queue / dead-letter 2026-05-10 00:01:06 +08:00
task_queue_test.go perf(wiki-ingest): scale to 4w-doc KBs + generic task queue / dead-letter 2026-05-10 00:01:06 +08:00
tenant.go feat(system): consolidate system admin and settings into one Settings panel 2026-05-26 21:13:56 +08:00
tenant_disabled_shared_agent.go feat(agent): enhance agent and skill management features 2026-02-09 11:40:25 +08:00
tenant_invitation.go feat(rbac): add multi-use share-link invitations for invite_only mode (#1504) 2026-05-27 19:42:01 +08:00
tenant_member.go fix(repository): qualify tenant_id with table name to resolve ambiguous column reference 2026-05-21 21:22:41 +08:00
tenant_test.go fix(tenant): prevent api_key encryption loss on tenant settings update 2026-03-25 21:25:21 +08:00
user.go feat(system): consolidate system admin and settings into one Settings panel 2026-05-26 21:13:56 +08:00
user_resource_favorite.go feat(favorites): implement user favorites and recents functionality 2026-05-18 17:28:58 +08:00
vectorstore.go feat: add VectorStore service layer with types and connection testing 2026-04-13 22:57:17 +08:00
web_search_provider.go feat(web-search): refactor web search provider 2026-03-31 20:22:34 +08:00
wiki_log_entry.go perf(wiki): move ingest log to event table and index to on-demand API 2026-05-08 21:48:52 +08:00
wiki_log_entry_test.go perf(wiki): move ingest log to event table and index to on-demand API 2026-05-08 21:48:52 +08:00
wiki_page.go fix(wiki-ingest,asynqdl): review fixups for PR #1241 2026-05-10 00:01:06 +08:00
wiki_page_test.go perf(wiki): move ingest log to event table and index to on-demand API 2026-05-08 21:48:52 +08:00