Commit Graph

1164 Commits (6e2e5d8bb07cd9c8db360c03b80ca47ea2e81fd5)

Author SHA1 Message Date
lyingbug c3f077ed18
fix(models): align configuration and multimodal embedding workflows (#4080)
* fix(models): align configuration defaults and multimodal workflows

* feat(image): enhance image retrieval diagnostics and filtering

- Implemented `retrieveObservedImagePool` to observe engine calls and record image recall decisions without altering results.
- Added detailed diagnostics in `summarizeImagePool` and `summarizeImageCandidateCut` to track image filtering decisions and scores.
- Introduced tests for image pool diagnostics to ensure accurate filtering and decision recording.
- Updated existing functions to utilize new retrieval and summarization methods for improved observability and accuracy in image handling.

* feat(embeddings): enhance image handling with new formats and message support

- Introduced `EmbeddingImageFormat` to manage image input formats, allowing for both object and messages formats.
- Updated `EmbeddingsSettings` to include new fields for `ImageFormat`, `ImagePrompt`, and `TextAsMessages` to support multimodal embedding workflows.
- Enhanced `Client` methods to build request bodies for images in both formats, ensuring compatibility with vLLM's requirements.
- Added tests to validate the new image message handling and ensure correct request formatting for different scenarios.
- Updated documentation to reflect changes in image input handling and configuration options.

* feat(similarity): add embedding similarity mode for enhanced document scoring

- Introduced a new `similarity` option in `ModelDebugOptions` to score documents and an optional image against a query.
- Updated `ModelDebugDrawer.vue` to support a new input mode for similarity, allowing users to select similarity as an input type.
- Enhanced the UI to display similarity results, including ranked candidates based on cosine similarity.
- Added tests to validate the functionality of the new similarity mode in embedding models.
- Updated localization files to include new strings related to similarity mode in multiple languages.

* feat(embeddings): add Qwen3-VL-Embedding support for multimodal input

- Introduced Qwen3-VL-Embedding model with support for both text and image inputs.
- Updated model configuration files to include compatibility settings for the new embedding type.
- Enhanced tests to validate the functionality of Qwen3-VL-Embedding, ensuring correct handling of inputs and outputs.
- Updated documentation to reflect the new model's capabilities and usage instructions.

* test(models): wrap embedding assertions to satisfy lint

* test(opensearch): isolate HTTP transports between parallel tests
2026-10-10 11:06:00 +08:00
lyingbug 65f88f4121
feat: judge image hits by their image in rerank and show them to vision models (#4013)
* feat(models): expose embedding input modalities

Whether an embedding model maps images into the same space as text is
what will decide if a knowledge base can store image vectors. The
catalog already had the field, but most multimodal embedding models
were missing it and embedding rows never reported it.

- Catalog: declare input modalities for the Doubao and Tongyi vision
  embeddings, the Aliyun multimodal / qwen-vl embedding families and
  jina-embeddings-v4, as listed in each vendor's documentation. The
  migration baseline changes for exactly these nine entries.
- Model responses resolve capabilities for embedding rows too, so
  capabilities.input reflects the catalog merged with spec.input.
- Model editor: an "Image input" switch for embedding models. It follows
  the catalog and writes spec.input only when the row differs from it;
  picking another catalog model or switching vendor drops the
  declaration. Model cards show the image badge for such models.

* feat(embedding): embed images with multimodal embedding models

Adds the image side of an embedder, for models that map images into the
same space as their text vectors so a text query can find an image.

- api: EmbedImage (bytes + MIME type, sent inline as base64 because the
  object store is usually unreachable from the vendor) and an
  ImageEmbedder implemented by all four protocols, each in the image
  shape its reference documents: Ark image_url, DashScope contents[].image,
  Gemini inlineData parts, and on the OpenAI shape an object keyed by the
  vendor's image_field (Jina: "image"). A plain OpenAI-compatible
  endpoint names no image field and takes no images.
- Settings: image_field, max_image_batch_size (default one per request),
  max_image_bytes and image_mime_types, filled from vendor docs for the
  DashScope multimodal models, gemini-embedding-2 and Jina.
- embedding: an optional ImageEmbedder interface reached through
  AsImageEmbedder, so existing Embedder implementations and fakes are
  untouched. An embedder takes images only when the catalog (or the
  row's spec.input) lists image AND the endpoint can carry one. Images
  are checked against the documented limits before any request, then
  split at the documented images per request. The concurrency, debug
  and Langfuse decorators forward it; logs and traces carry the MIME
  type and size, never the bytes.

The migration baseline changes only for the entries whose resolved
embedding settings now carry image limits.

* feat(knowledge): index images by their own vector and recall them

When the knowledge base's embedding model embeds images, each image now
gets a vector of its own next to its caption and OCR chunks, so a query
can find an image by what it shows even where the caption left it out.

Ingestion
- After the caption/OCR chunks are indexed, the multimodal task embeds
  the image (embedding.PrepareImage converts and shrinks it to the
  vendor's documented limits) and stores it as a new image_vector chunk:
  Content is the caption (OCR text when there is none) for reranking and
  the answer context; its index row carries the image's vector with
  SourceType ImageSourceType. Scanned PDF pages are skipped, their OCR
  text serves better. A failure here is logged and never fails the task.
- The image vector gets its own chunk rather than a second index row on
  the caption chunk: OpenSearch and Weaviate key documents by ChunkID,
  so a second row would overwrite the caption's text vector, and copy,
  move and enable/disable all follow chunk IDs.
- CompositeRetrieveEngine.BatchIndexVectors writes precomputed vectors
  through each engine's normal BatchIndex, keeping row order (the
  composite's de-duplication does not).
- Paths that rebuild vectors from text leave image_vector alone:
  syncChunkIndex only syncs its enabled flag, updateChunkVector skips
  it, and a caption edit updates its Content only.
- The multimodal task's caption/OCR index rows now set IsEnabled; only
  backends with a column default were storing them as enabled.

Retrieval
- A text query scores lower against an image than against text, so when
  the model embeds images the document vector search is widened by half
  (capped at 500) and run at min(VectorThreshold, 0.1); each store
  group's hits are then held to their own threshold before score
  normalization: text at VectorThreshold, images at min(VectorThreshold,
  0.1). Keyword hits on image rows are dropped, their Content being the
  already-indexed caption.
- image_vector hits are searchable and merge like caption hits: parent
  context is attached, and the caption is not repeated from ImageInfo.

Adds golang.org/x/image for scaling and WebP/BMP decoding.

* fix(models): report no thinking levels for embedding, rerank and ASR models

Embedding rows now carry capabilities, and the end-to-end run showed them
listing off/auto/minimal/low/medium/high: these references resolve no chat
protocol, and an empty level map reads as "every level supported". A model
without a chat protocol does not think, so its capabilities say so.

* fix(compaction): never read a cancelled turn's stream as a summary

streamSummary selects on the turn's context and the provider stream at
once. When the turn is already cancelled both are ready (providers close
the stream once their context ends), and select picks at random, so a
stopped turn could come back as a completed, partial summary with a nil
error. TestSummarizationIsNotRetriedOnceTheTurnIsCancelled caught it
intermittently in CI and reproduces under -race with several -cpu values.

Check the context before each receive and again when the stream closes.

* feat(rerank): score images with multimodal rerank models

Rerank models that read images can now be sent an image document and
score it against a text query on the same scale as text, which is what a
recall made by an image's own vector needs: a text reranker only sees the
caption, and rejects an image for what the caption left out.

- api: ImageReranker, implemented by the Cohere and NIM shapes. Image
  documents go in requests of their own, so text requests keep their
  exact shape. NIM sends image-only passages without text, as base64 data
  URLs (its VLM reranking reference requires both). The Cohere shape sends
  {"<image_field>": data URI} documents and asks for no echo of them.
- The image settings embeddings already had (image_field,
  max_image_batch_size, max_image_bytes, image_mime_types) move into a
  shared ImageInput embedded in both settings; resolved embedding settings
  serialize exactly as before.
- Catalog: jina-reranker-m0 and nvidia/llama-nemotron-rerank-vl-1b-v2 take
  text and image. Jina names "image" documents; its base64 form is not
  shown in any reranker example, so the data URI its embeddings reference
  documents is used and marked unverified. NVIDIA lists its six formats
  and 512 passages per request.
- rerank: an optional ImageReranker reached through AsImageReranker, gated
  on the model's catalog input and the endpoint; images are checked against
  the documented limits before any request, scores are normalized like
  text, and the debug and Langfuse decorators forward it without logging
  image bytes.
- Image preparation (format conversion, shrink to fit) moves from the
  embedding package to internal/models/imageprep, since rerank needs it
  too.

* feat(retrieval): keep a vector hit's own similarity through fusion

Hybrid fusion replaces a hit's Score with a rank-based RRF score. That is
right for ordering, but it erases the evidence reranking needs to judge an
image found by its own vector: how close the vector actually was. Record
the engine's similarity on each vector hit (IndexWithScore.VectorScore)
before normalization and fusion rewrite Score, and carry it onto the
search result (SearchResult.VectorScore, not serialized).

* feat(reranking): judge image hits by their image, not only their caption

An image found by its own vector was reranked on its caption and OCR text,
so a text reranker rejected it for exactly what the caption left out.

- With a reranker that reads images and a LoadImage callback, image_vector
  hits are scored by their image (prepared to the model's limits) on the
  same scale as text, and pass or fail the same threshold. A hit whose
  image cannot be read, prepared or scored falls back to its text.
- With a text reranker, its verdict stands for images that are mostly
  text (OCR of 200 characters or more). A pictorial hit it rejects is kept
  when its vector similarity (VectorScore) reaches Options.ImageKeepScore:
  at most two, strongest vector first, appended after the ranked results
  and marked kept_by=image_vector. This also returns an image when no text
  passes at all.
- Diagnostics report images_scored and images_kept.

* feat(rerank): read image hits' images in every rerank path

The chat pipeline, the agent search_knowledge tool and the hybrid-search
API now pass the rerank stage a way to read an image hit's image and an
image keep score, so a multimodal reranker scores images by what they show
and a text reranker can no longer drop a pictorial image its caption
undersells.

- KnowledgeBaseService.ReadChunkImage reads the first image of a result's
  image_info from the storage of its knowledge base (the knowledge base's
  tenant, so shared knowledge bases read from their owner's storage),
  capped at 32 MB. Plain http(s) images go through the SSRF-safe
  downloader.
- The backend resolution the image multimodal task used moves into a
  shared knowledgeImageReader, so ingestion and reranking find an image in
  the same place.
- reranking.ImageKeepScoreFor: an image is kept over a text reranker only
  when its vector was at least as close as a text hit had to be, and never
  below 0.25 (empirical).

* feat(chat): show a vision model the images its answer rests on

An image recalled by its own vector reached the answer as its caption only,
so a vision model could not answer from what the caption left out.

- Knowledge QA: INTO_CHAT_MESSAGE reads, for a model that supports vision,
  the images of the contexts that rest on an image vector match (at most
  three distinct ones, prepared to what every vision API takes: PNG, JPEG,
  WebP or GIF within 5 MB), attaches them after the user's own images, and
  names the contexts they belong to.
- Agent: search_knowledge attaches the same images when the agent's model
  supports vision (the agent describes tool images to models that cannot
  see them, and these already carry captions). Stored history drops them;
  they are read again from storage.
- An image hit and its caption hit read the same once merged, and
  de-duplication keeps either. The kept copy now inherits the image
  (image_vector_match), in the pipeline's exact and partial-overlap
  de-duplication and in the agent tool's.
- Results the rerank stage kept outside its top-k (kept_by) no longer fall
  to the later top-k cuts: the pipeline's FilterTopK and the agent tool's
  MMR and limit let them ride along after the ranked results.

* docs(website): describe how image hits are reranked and shown to vision models

* Fix image evidence preservation and model source mapping
2026-10-09 13:01:48 +08:00
tayadwx a1450d382e
fix(knowledge): claim cloned and released document images in the resource catalog (#3752)
* fix(knowledge): claim cloned and released document images in the catalog

#3493 binds images at parse time (bindStoredImages), which covers ingestion
but not the two paths that move image ownership:

Clone. A copied image is written as a new object, yet nothing claimed it for
the destination knowledge, so the KB file proxy answered 403 and cloned
documents rendered without images. The copy now goes through SaveBytes into
the servable exports/ namespace (CopyFile wrote to the knowledge-scoped
upload layout the proxy rejects), is claimed by the destination knowledge,
and CloneChunk / FAQ clone bind the handles left in chunk content and
image_info.

Delete. Release only looked at multimodal ImageInfo, which stays empty for
documents whose images live in markdown alone, so those objects outlived the
knowledge that owned them. The release set is now the union of ImageInfo URLs
and the bindings recorded for the knowledge being removed, with source_file
excluded so reparse and cleanup keep the original document.

The parse-path claim from the earlier attempt is dropped: ProcessDocument
already gets it from bindStoredImages, and the removed test only string
matched that call in the source. Every claim path stays best-effort,
including the clone path, which used to fail the whole clone and delete the
fresh copy when a single Bind errored.

* fix(knowledge): keep markdown-only images out of the pre-reindex cleanup

cleanupKnowledgeResources runs before a knowledge is re-indexed -- a manual
update, a reparse, a move with reparse -- not before it is removed. Unioning
in the catalog bindings there released a solely owned markdown-only
attachment, deleteExtractedImages deleted the file, and the catalog file
service marked the resource deleted. The re-claim that runs after the cleanup
resolves through a state=active lookup, so it could never bind that handle
again: the republished body was left pointing at a deleted image.

Cleanup collects ImageInfo URLs alone again. The paths that do remove a
knowledge entry (executeKnowledgeDelete, ProcessKBDelete) keep the union, which
is what lets markdown-only images be released when the knowledge actually goes
away.

Reported by @lyingbug in review on #3752.

---------

Co-authored-by: tayadwx <tayadwx@users.noreply.github.com>
2026-10-09 13:01:26 +08:00
helloxjade 4243018ff1
fix(mcp): report advertised directory failures in connection tests (#3905)
* fix(mcp): report tool listing failures in connection tests

* fix(mcp): preserve discovery for unadvertised capabilities

* fix(mcp): resolve connection test lint findings
2026-10-09 12:01:27 +08:00
helloxjade 09411106f0
fix(session): allow tenant admins to manage channel sessions (#3939)
* fix(session): allow tenant admins to manage channel sessions

* fix(session): restrict admin management to channel sessions
2026-10-09 12:00:07 +08:00
linus-liu-web abc365f919
fix(wiki): 唯一写出口 UpdatePage 拦住丢表格行的机器重写(agent 整页写入不再静默改短页面) (#3793)
* fix(wiki): 在唯一写出口 UpdatePage 拦住丢表格行的机器重写

模型被要求把整页重新吐一遍时,markdown 表格是最常出错的地方:一百行的
证书台账回来只剩三十行,finish_reason=stop、没有任何报错,页面历史里就是
一次普通编辑。守卫因此加在 UpdatePage —— 所有调用方共用的唯一写出口,
而不是某一个调用方。

- 按「每行第一个非空单元格」的身份集合比较新旧内容(去掉强调符号、折叠
  空白、统一大小写):换行、重排、改日期/金额列都不算丢行,只有一行指向
  的实体整个消失才算;
- 同一身份出现两次按多重集比较,丢掉其中一行同样是丢;
- 表头行(`| --- |` 的上一行)不参与比较,模型改列名不算丢行。

有意的缩短放行:人在页面上删行(user)、回滚到更短的旧版本(revert),
以及调用方用 types.WithWikiShrinkAllowed 明确标注的写入 —— ingest 的
retract 轮(源文档被删除,被删文档名下的行本来就该消失)与 agent 的精确
文本替换(old_text 必须逐字命中现有内容,删除是有意为之)各自在自己的
写入上打这个标记。

agent 的整页写入拿到的是错误而不是静默成功:否则模型会以为改了一页、其实
一个字节都没动;它可以把那几行重新吐出来,或改用精确替换工具。

测试:身份比较、多重集、表头跳过、散文中孤立竖线不算表格;sqlite 上的
UpdatePage 拒绝写入且版本不推进、四类放行都能写进去、正常重写照常落库。
反向验证两组:去掉豁免 → 4 个放行用例 FAIL;让身份比较失效 → 6 个用例
FAIL(含两个 UpdatePage 用例);文件逐字节还原后全 PASS。

* fix(wiki): 拒写要向调用方明说,否则 trim 会删掉没落地的文档

UpdatePage 的守卫对非 agent 来源是**静默拒写**(返回现有页面 + nil
error)—— 页面本身没坏,这个选择是对的。但对 ingest 这条调用链来说,
"静默"本身就是个洞:

  reduceSlugUpdates 拿到 err == nil
    → 返回 changed=true, err=nil
    → 调用方那句 `if reduceErr != nil { collectUnapplied(updates) }` 走不到
    → trim 阶段认为这个 slug 已经成功合并
    → 把它背后的文档删掉
    → 而这些文档的贡献从来没写进页面,下一批也不会再回来

collectUnapplied 是"这些文档别删、下一批再来"的唯一入口,全仓只有三个
调用点(lockErr / !acquired / reduceErr != nil),没有一个能覆盖静默拒写。

修法不改 UpdatePage 的契约:拒写时它返回的是**未经改动的页面**,所以
调用方比较写入前后的 Version 就能判断,然后把 updateDeferred 一路带出去,
交给 collectUnapplied —— 与 #3617 的 updateDeferred 语义一致。

补的是 #3617 里这块语义;守卫本身仍在唯一写出口(不改架构)。
本提交只补连线,没有新增单测:这条路径要 asynq + chat model 的整套夹具,
而"静默拒写返回 nil"这一前提已由 TestUpdatePageRefusesARewriteThatDropsTableRows 覆盖。

* fix(wiki): 表格行守卫按去重身份集算比例,拒写改用显式信号

- agent 整页更新仍是任一身份缺失即拒写;ingest(未显式允许缩减)改为
  丢失超过旧内容唯一身份数 20% 才拒写,user/revert/显式允许缩减不变
- wikiWriteMissingRowIdentities 改为集合比较:同身份的两行合成一行不再
  算丢失;身份只取首个非空单元格,注释与日志都写明这个边界
- UpdatePage 的拒写统一返回 ErrWikiWriteDroppedTableRows;reduce 用
  errors.Is 区分"守卫拒写"与"成功但版本未变",不再拿版本号当信号,
  只有确实未落地的贡献才保留关联文档重试

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
Co-authored-by: linus-liu-web <linus-liu-web@users.noreply.github.com>
2026-10-09 10:55:28 +08:00
linus-liu-web cbfc0fed4a
fix(chat): 在模型上下文中标注 FILTER_TOP_K 的子集截断,避免把前 N 条当作全集作答 (#3758)
* fix(chat): 在模型上下文中标注 FILTER_TOP_K 的子集截断

FILTER_TOP_K 排序后直接 searchResult[:topK],模型只拿到 topK 条却按全集
语气作答(聚合类问题最明显:名单只被截取排名靠前的若干条,模型仍输出
"这些人是……"),属于完整但错误的答案。

本次只让截断对模型可见:真正丢结果时记录 RetrievalTruncation{Shown,
Candidates};prepareMessagesWithModelContext 把它作为 retrieval_shown /
retrieval_candidates 传给 modelcontext;annotateSearchNotes 在
<retrieval> 内追加 <subset shown="N" candidates="M">,说明这里只是排名
靠前的若干条、无法据此给出完整名单或精确计数。未截断时字段为 nil,不产
生任何标注。

提示落在 model context 视图(模型真正读到的那份)而不是
RenderedContexts:后者会被 prepareMessagesWithModelContext 整段替换成
<retrieval> 视图,写在那里的说明到不了模型。

不做日志:截断几乎每次检索都会触发,#3565 把 info 升 Warn 已被维护者以
"只会变噪音"否决;这里要解决的是模型看不到截断,不是运维看不到。

不动检索策略:不提高 topK、不改召回与重排,避免影响既有延迟和答案质量。

测试(夹具为合成数值):
- filter_top_k_test.go:截断时 Truncation={Shown:topK,Candidates:before},
  未截断(结果数 ≤ topK)时为 nil;
- modelcontext/omitted_results_test.go:带 retrieval_shown=5 /
  retrieval_candidates=48 时输出 <subset shown="5" candidates="48"> 且仍
  以 </retrieval> 结尾;shown==candidates 或计数缺失时不出现;
- references_test.go:Truncation 非 nil 时最终 model context 含
  <subset shown="3" candidates="48">,nil 时不含;另有端到端用例串起
  FILTER_TOP_K → INTO_CHAT_MESSAGE → prepareMessagesWithModelContext,确认
  提示到达模型消息而不是被替换掉。

* fix(chat): 截断提示改条件式并覆盖重排/合并的提前裁剪

评审意见(#3758):原提示无条件要求模型 "say the answer may be incomplete",
会让普通事实问答也带上免责声明;且重排阶段与 merge 回退已可能提前裁剪,
FILTER_TOP_K 不再截断时这条提示根本不生成。

- subset 提示改用评审给定的条件式措辞:只有问题在计数或要求完整列举时
  才说明结果范围,其他问题照常回答;N/M 填实际计数
- 明确 M 的语义:它是首次裁剪阶段(rerank / merge / filter_top_k)收到的
  候选片段数,不是全库匹配总数
- 重排阶段的阈值过滤、候选上限与 MMR top-k 裁剪,以及 merge 回退到
  RerankTopK 的裁剪,都经 ChatManage.RecordRetrievalCut 记录;首次裁剪为准,
  后续更窄的裁剪不覆盖候选池
- references 用实际渲染的知识片段数作为 N;补重排提前裁剪、merge 提前裁剪
  到模型消息的端到端回归测试

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
Co-authored-by: linus-liu-web <linus-liu-web@users.noreply.github.com>
2026-10-09 10:54:37 +08:00
linus-liu-web 04da26024c
fix(weaviate): CopyIndices 补游标防护,并修掉 GraphQL 报错时的 panic (#3881)
* fix(weaviate): 复制索引时游标不前进立即报错,并给分页加跳数上限

CopyIndices 的游标由每页最后一个对象的 id 反推(repository.go:763),循环的
退出条件只有"查询出错"和"这一页为空"。源端只要重复返回同一页,游标就永远
停在同一个 id 上:循环把这一页反复读出、再反复 upsert 进目标库,直到复制任务
撞上 2 小时超时;源端在该页之后的数据永远读不到,而目标库里同一批 chunk 已经
被写成成千上万份候选向量。同包的 move.go 早就记录了 after+where 在 Weaviate
上不可靠,并为此用 seen 集合拦住"游标不前进",CopyIndices 用的正是这个组合,
却没有那层保护。

本次修改:

- 记录每个用过的游标,重复即返回 "copy indices made no progress at cursor",
  不再把"游标不动"当成"读完了"。检测点放在整页解析之后、批量写入之前,所以
  重复的那一页不会再多写一份。
- 分页跳数上限 maxCopyPaginationHops(10000 页,按每页 64 条合 64 万行,与
  confluence 的 maxPaginationHops 同量级);触顶时打印 Warn 并返回错误,而不是
  把这轮复制当成成功——静默截断会留下一个看起来正常的残缺索引。
- additional["id"] 从无检查断言改为带检查断言,缺 id 或 id 为空时返回错误;
  原先这里会 panic。同包 move.go 的 move index ID 已是这种写法。

回归用例用假 Weaviate 服务端复现两种源端形态:恒定返回同一页的源端在第二次
查询后被拦下(GraphQL 查询 2 次、目标库只写 64 条,而修复前 5s 内同一页被重放
4484 次、写入 286912 条);一直推进但永不结束的源端在第 10000 页被拦下。

* fix(weaviate): 复制索引时 GraphQL 层报错不再被当成"源已读完",也不再 panic

Weaviate 对于"执行不了的查询"返回的是 HTTP 200 + errors 数组 + 没有 data。SDK 的
runGraphQLQuery 只在 HTTP 状态异常时返回 error(weaviate-go-client 的
graphql/gql.go:136-150),所以这种响应到 CopyIndices 手里时 err == nil,而
result.Data 是 nil。

原代码只检查 err,随后一行完成两件事:

    objects, ok := result.Data["Get"].(map[string]interface{})[collectionName].([]interface{})

这里逗号-ok 只作用于最后一个断言,第一个 `.(map[string]interface{})` 是单值断言;
result.Data 为 nil 时该表达式的值是 nil 接口,单值断言直接 panic。实测
(假服务端返回 {"errors":[{"message":"class Weknora_embeddings_64 does not exist"}]}):

    panic: interface conversion: models.JSONObject is nil, not map[string]interface {}
        .../weaviate.(*weaviateRepository).CopyIndices(...)
            repository.go:753

也就是说复制任务在这种响应下不是"静默少拷",而是直接 panic;即便不 panic,把
"没有 data"当成"这一页为空"也会让一次失败的查询以 Index copy completed 收尾。

本次修改:

- 在 err 检查之后补 `len(result.Errors) > 0` → 记录日志并返回
  "weaviate: copy indices query failed: <message>",与同文件 VectorRetrieve
  (:608-611)、KeywordsRetrieve (:677-680) 以及同包 move.go:32-34 的既有写法一致。
- 把那一行的两级断言拆成两次逗号-ok 断言,响应缺 Get 或 class 键时返回
  "weaviate: copy indices invalid response",不再 panic。

回归用例 TestCopyIndicesReportsAQueryError:假服务端对所有 Get 返回上述 errors
响应,断言 CopyIndices 返回带原始 message 的错误(修复前是 panic),且只发一次
查询、没有把任何东西当成复制成功。

* test(weaviate): 补一个"响应读不出 data 时不得 panic"的复制用例

上一个提交把 `result.Data["Get"].(map[string]interface{})` 这一处单值断言拆成了两次
逗号-ok 断言,但只验证了"带 errors 的响应"那条路径:那条路径在 Errors 检查处就返回
了,走不到断言。这里补 TestCopyIndicesRejectsAResponseWithoutData,让假服务端返回
HTTP 200 + `{"data":{}}`(没有 errors,也没有 Get 键),断言 CopyIndices 返回
invalid response 而不是 panic;去掉断言拆分、只保留 Errors 检查时该用例必红。

两个用例都用 recover 把 panic 转成明确的用例失败,避免一个 panic 直接终结整个测试
二进制、连带吞掉同包其它用例的结果。

* fix(retriever/weaviate): CopyIndices 按映射分块读源行,去掉会被服务端拒绝的游标

CopyIndices 用 where + after 遍历源知识库,而 Weaviate 的游标 API 不允许过滤条件
与 after 同时出现:ValidateCursor 直接返回 "where cannot be set with after and
limit parameters",且 client 第一页就会把 WithAfter("") 发成 after: "",所以这个
查询在真实服务端上一页都跑不通。该报错以 HTTP 200 + errors 返回,不检查 errors 的
代码会把它当成"源已读完",返回成功但一条都没复制(本 PR 已补的 errors 检查会把它
变成错误,但那是在暴露一个本就不合法的查询)。即使去掉 where,游标仍然是"跨请求
保持不变的结果顺序"上的位置,服务端不承诺维持该顺序,一旦漂移就会漏行且仍报成功。

改成按映射里的源 chunk ID 分块读:谓词 = knowledge_base_id 相等 AND chunk_id
ContainsAny(本批 64 个),不带 after。读到的行集合由谓词唯一确定,没有游标可漂。

同一个 chunk 会有正文向量 + 多个生成问题向量,64 个 ID 不等于最多 64 行,所以每批
查询显式带 limit(QUERY_MAXIMUM_RESULTS,v1.37.3 默认 10000)。该配置没有客户端
接口(/v1/meta 只有 version/hostname/modules),先按默认值查,被服务端以
"query maximum results exceeded ... QUERY_MAXIMUM_RESULTS 'N'" 拒绝时按 N 降级
重试。一批返回行数达到 limit 说明可能被截断,对该批对半拆分重查直到单个 chunk;
单个 chunk 仍然填满 limit 时明确报错(含 chunk ID 与服务端上限),绝不返回复制成功。
不带 limit 的 GraphQL Get 会落到 QUERY_DEFAULTS_LIMIT_GRAPHQL(100) 静默截断。

页数上限(maxCopyPaginationHops)与重复游标防护随游标一起去掉:读取范围由映射
限定,不存在走不完的分页。GraphQL errors 检查与 data["Get"]、_additional["id"]
的逗号-ok 解包保留。

测试:copy_test.go 的假服务改成按 chunk_id 过滤的真实形状,并像 v1.37.3 一样拒绝
where+after 组合(假服务会断言这种组合从未出现);补同一 chunk 多向量、批次触顶
拆分、单 chunk 超限报错、QUERY_MAXIMUM_RESULTS 降级四类用例。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
Co-authored-by: linus-liu-web <linus-liu-web@users.noreply.github.com>
2026-10-09 10:47:30 +08:00
lyingbug 0c5d28abb7
feat: index and recall images with multimodal embedding models (#3683)
* feat(models): expose embedding input modalities

Whether an embedding model maps images into the same space as text is
what will decide if a knowledge base can store image vectors. The
catalog already had the field, but most multimodal embedding models
were missing it and embedding rows never reported it.

- Catalog: declare input modalities for the Doubao and Tongyi vision
  embeddings, the Aliyun multimodal / qwen-vl embedding families and
  jina-embeddings-v4, as listed in each vendor's documentation. The
  migration baseline changes for exactly these nine entries.
- Model responses resolve capabilities for embedding rows too, so
  capabilities.input reflects the catalog merged with spec.input.
- Model editor: an "Image input" switch for embedding models. It follows
  the catalog and writes spec.input only when the row differs from it;
  picking another catalog model or switching vendor drops the
  declaration. Model cards show the image badge for such models.

* feat(embedding): embed images with multimodal embedding models

Adds the image side of an embedder, for models that map images into the
same space as their text vectors so a text query can find an image.

- api: EmbedImage (bytes + MIME type, sent inline as base64 because the
  object store is usually unreachable from the vendor) and an
  ImageEmbedder implemented by all four protocols, each in the image
  shape its reference documents: Ark image_url, DashScope contents[].image,
  Gemini inlineData parts, and on the OpenAI shape an object keyed by the
  vendor's image_field (Jina: "image"). A plain OpenAI-compatible
  endpoint names no image field and takes no images.
- Settings: image_field, max_image_batch_size (default one per request),
  max_image_bytes and image_mime_types, filled from vendor docs for the
  DashScope multimodal models, gemini-embedding-2 and Jina.
- embedding: an optional ImageEmbedder interface reached through
  AsImageEmbedder, so existing Embedder implementations and fakes are
  untouched. An embedder takes images only when the catalog (or the
  row's spec.input) lists image AND the endpoint can carry one. Images
  are checked against the documented limits before any request, then
  split at the documented images per request. The concurrency, debug
  and Langfuse decorators forward it; logs and traces carry the MIME
  type and size, never the bytes.

The migration baseline changes only for the entries whose resolved
embedding settings now carry image limits.

* feat(knowledge): index images by their own vector and recall them

When the knowledge base's embedding model embeds images, each image now
gets a vector of its own next to its caption and OCR chunks, so a query
can find an image by what it shows even where the caption left it out.

Ingestion
- After the caption/OCR chunks are indexed, the multimodal task embeds
  the image (embedding.PrepareImage converts and shrinks it to the
  vendor's documented limits) and stores it as a new image_vector chunk:
  Content is the caption (OCR text when there is none) for reranking and
  the answer context; its index row carries the image's vector with
  SourceType ImageSourceType. Scanned PDF pages are skipped, their OCR
  text serves better. A failure here is logged and never fails the task.
- The image vector gets its own chunk rather than a second index row on
  the caption chunk: OpenSearch and Weaviate key documents by ChunkID,
  so a second row would overwrite the caption's text vector, and copy,
  move and enable/disable all follow chunk IDs.
- CompositeRetrieveEngine.BatchIndexVectors writes precomputed vectors
  through each engine's normal BatchIndex, keeping row order (the
  composite's de-duplication does not).
- Paths that rebuild vectors from text leave image_vector alone:
  syncChunkIndex only syncs its enabled flag, updateChunkVector skips
  it, and a caption edit updates its Content only.
- The multimodal task's caption/OCR index rows now set IsEnabled; only
  backends with a column default were storing them as enabled.

Retrieval
- A text query scores lower against an image than against text, so when
  the model embeds images the document vector search is widened by half
  (capped at 500) and run at min(VectorThreshold, 0.1); each store
  group's hits are then held to their own threshold before score
  normalization: text at VectorThreshold, images at min(VectorThreshold,
  0.1). Keyword hits on image rows are dropped, their Content being the
  already-indexed caption.
- image_vector hits are searchable and merge like caption hits: parent
  context is attached, and the caption is not repeated from ImageInfo.

Adds golang.org/x/image for scaling and WebP/BMP decoding.

* fix(models): report no thinking levels for embedding, rerank and ASR models

Embedding rows now carry capabilities, and the end-to-end run showed them
listing off/auto/minimal/low/medium/high: these references resolve no chat
protocol, and an empty level map reads as "every level supported". A model
without a chat protocol does not think, so its capabilities say so.

* fix(compaction): never read a cancelled turn's stream as a summary

streamSummary selects on the turn's context and the provider stream at
once. When the turn is already cancelled both are ready (providers close
the stream once their context ends), and select picks at random, so a
stopped turn could come back as a completed, partial summary with a nil
error. TestSummarizationIsNotRetriedOnceTheTurnIsCancelled caught it
intermittently in CI and reproduces under -race with several -cpu values.

Check the context before each receive and again when the stream closes.

* feat(knowledge): put image vectors behind a knowledge-base switch, off by default

Image vector indexing and recall used to turn on whenever the knowledge
base's embedding model declared image input. A model that takes images is
often chosen for text alone, so an upgrade would have added an embedding
call per image, widened vector recall 1.5x and lowered the image threshold
to 0.1 for those knowledge bases without anyone asking.

ImageProcessingConfig gains image_vector_enabled (default false; stored
JSON without the key reads as off, so existing knowledge bases stay off
with no migration). Both sides now need the switch and the model:

- indexImageVector returns before touching the model unless the KB opted
  in (KnowledgeBase.IsImageVectorEnabled, which also needs vector indexing).
- applyImageRecall resolves the embedding model only when some KB in the
  search opted in, and records the opted-in KBs per store group
  (storeGroup.ImageKBIDs). Only those groups widen the pool and lower the
  threshold; image hits of any other KB, including ones indexed before the
  switch was turned off, are dropped.

The KB editor shows the switch in the image processing section, with a
warning when the selected embedding model does not declare image input;
docs describe the switch, its cost and what turning it off does.

* fix(knowledge): leave image vectors behind when cloning into a KB that is off

CloneChunk copied every chunk of the source document and then CopyIndices
for all of them, so copying a document from a knowledge base with image
vectors on into one with the switch off (same model and store) still
created image_vector chunks and their index rows, bypassing the switch
that indexImageVector honours.

Image vector chunks are now dropped from the copy when the target has not
opted in. Every engine's CopyIndices copies only the rows of chunks in the
mapping, so their index rows stay behind too.

* fix(search): refill the vector pool past stale image vectors

Image hits of a knowledge base whose switch is off were dropped only after
the engine had ranked and cut its results at TopK. Image vectors indexed
before the switch was turned off could fill that pool and push out valid
text hits: with MatchCount 5 the pool is 50, and 50 stale image rows
ranked above the text left the search empty.

No engine can filter rows by source type (Postgres and SQLite do not even
take ExcludeChunkIDs), so the exclusion cannot move into the query. When
the document vector pool comes back full and holds stale image rows, that
search alone runs again on a pool twice as large, until it holds TopK rows
that are not stale, the index runs out, or the pool reaches
maxRetrievalPoolSize (at most four extra calls from a pool of 50). The pool
is then cut back to TopK such rows, matching an engine-side exclusion
unless more than maxRetrievalPoolSize-TopK stale rows rank above the text.

* feat(i18n): translate the image vector switch and image input keys into zh-TW

The zh-TW locale arrived from main after this branch added five keys: the
knowledge base's image vector switch (label, description, unsupported-model
warning) and the embedding model's image input flag (label, description).

* fix(knowledge): leave image vectors behind when moving into a KB that is off

A reuse_vectors move relocates a document's chunks and index rows in place:
MoveKnowledgeIndices rebinds the rows by document ID and
MoveChunksByKnowledgeID rebinds the chunks. Moving a document from a
knowledge base with image vectors on into one with the switch off therefore
carried its image_vector chunks and their vectors along, the same bypass the
clone path had.

When the target has not opted in, the image_vector chunks are now deleted
during the move, their index rows first and then the chunks, so a retry
finds the chunks again rather than leaving orphaned rows. A target that
opted in still receives them unchanged.

* fix(retriever): keep image vectors out of keyword-only engines

BatchIndexVectors handed image rows to every engine of the composite,
including one that serves keyword retrieval alone (Elasticsearch v7 next to
a vector store). There the row holds nothing but the image's caption, which
the caption's own chunk already indexes, and retrieval discards every
keyword hit on it.

Image rows now go only to engines that serve vector retrieval. An engine
that serves both keeps one row for both kinds, so its keyword search still
meets them; the search side handles that.

* fix(search): refill the keyword pool past image rows

Every engine that serves both kinds of retrieval stores one row per index
entry and runs its keyword search over that row's content, so an image
vector row, whose content is its caption, is a keyword hit wherever the
caption's own chunk is. filterImageHits drops all of them, but only after
the engine has cut its ranking at TopK, so they crowded out text and caption
hits; a keyword ranking that put the image rows first came back empty.

The keyword pool is now refilled the way the vector pool is refilled past
stale image vectors: when it came back full and held image rows, the
keyword search runs again on a pool twice as large, up to
maxRetrievalPoolSize, and is cut back to TopK hits that are kept.

Leaving the rows out of the keyword index instead would mean writing them
without searchable content (Milvus and Tencent VectorDB derive a BM25
sparse vector from it, and how they take an empty one is unverified) or a
source-type filter in every engine's keyword query (ten engines, and
filterable fields that existing collections lack).

* revert: let image vectors move with the document into a KB that is off

This reverts commit e259977fe915f7d0bc30c4b02bc7af04da1c8dd4.

Deleting the image vector index rows by chunk ID before the move is not
reliable: the Weaviate and Elasticsearch v8 delete wrappers ignore partial
failures, and OpenSearch rejects more than 1000 IDs with ErrBatchTooLarge.
A partial delete followed by the chunk delete leaves index rows whose chunks
are gone, which nothing ever cleans up.

Without it, the image_vector chunks and their index rows move together
with the document. While the target's switch is off they are filtered at
query time (the pool refill keeps them from crowding out text), they are
removed with the document on delete, reparse or knowledge base delete, both
chunks and index rows by knowledge ID, and they become active again if the
target turns the switch on. The clone path keeps dropping them, since there
the rows are copied rather than moved.

* fix(search): keep the image row refill from losing hits it already had

refillPool replaced a pool with the answer to each larger search. A refill
that answered only in part (RetrieveResult.Error, swallowed into a warning
by retainPartialResults, as when some collections of the store did not
answer) could hold fewer text rows than the complete smaller pool, or none:
40 stale image rows above 10 text came back from a partial refill as the
40 image rows alone, and the search lost all 10 text hits. A refill that
failed outright failed the whole store group, discarding a first round that
had succeeded.

A refill is now best effort. A failed or incomplete refill search stops
the refill and leaves the last complete pool in place, cut back to TopK
kept rows as before, so a refill can no longer leave a search worse off
than it was without it. Merging the partial answer into the pool was not
done: its rows would need deduplicating and its ranking is cut at a
different TopK over a different set of collections, while keeping the
previous pool is exact.

* docs(knowledge): say what happens to image vectors in a KB that is off and what the refill costs

The image vector section now says that with the switch off, image vectors
that were indexed before it was turned off, or that came along when the
document was moved in from a KB that has it on, are kept but filtered at
query time, are removed when the document is deleted or reparsed or the
KB is deleted, and are recalled again once the switch is turned on; a copy
into such a KB leaves them behind.

It also states the cost of keeping dropped image rows from crowding text
out of the pools: the vector and keyword pools are searched again with
TopK doubled up to the 500 candidate cap, which adds queries for store
groups that hold such rows, and text can still be missed when more than
about 500 candidates are image rows. A failed or partial refill keeps the
previous complete pool.

* fix(search): log unexpected refill result sets, and describe the refill stop condition precisely
2026-10-08 18:19:53 +08:00
zaqqmm 19542f2a1d
feat(datasource): add Seafile data source connector (#3616)
* fix(datasource): omit last_sync_cursor from the data source list response

The settings page polls GET /datasource every few seconds during a sync,
and connector cursors can grow to megabytes. No list consumer reads the
cursor, so NewDataSourceResponses now blanks it; detail, create and
update responses still return it through NewDataSourceResponse.

* feat(datasource): add Seafile connector with fingerprint-based incremental sync

Sync folders and files from one Seafile library per data source. The
connector walks the selected scope one directory level at a time,
downloads files through the link + fileserver flow without credentials,
and reconciles deletions against a per-file oid/mtime/size fingerprint
cursor that is checkpointed every 50 mutations.

- resource ids are "<repo_id>:<path>"; ancestors collapse, one library
- per-file failures become coded error items and keep the path pending
- directory failures and Retry-After > 60s abort without deletions
- forced full runs keep the old cursor as a deletion baseline
- API token never reaches cursors, metadata, logs or error text
- share the supported import extension set through internal/utils

* feat(datasource): add Seafile frontend connector and docs

Wire the Seafile data source into the editor dialog, channel labels
and the five locales, and document how to connect a Seafile 10.0.1
library.

- connector definition with base_url + API token fields and icon
- picker guard: one library per data source, at least one selection
- "library" resource type and icon in the lazy tree
- channel label in the knowledge base filter, document views and chat
- i18n for labels, guide steps and the eight seafile_* sync error codes
- website-docs integration guide, data source and extension point doc
  updates, and Seafile in the README data source lists

---------

Co-authored-by: zaqqmm <q-zhang10@qq.com>
2026-10-08 16:18:09 +08:00
LuckVd b5c8d90cc2
fix(chat_pipeline): treat non-JSON model refusals as skipped graph extraction (#3606)
* fix(chat_pipeline): treat non-JSON model refusals as skipped graph extraction

When a chunk carries nothing extractable (e.g. a table-of-contents page),
the LLM correctly answers with a prose refusal such as "抱歉…". parseOutput
then fed that prose to json.Unmarshal, failing with a confusing
"invalid character 'æ'" (the first byte of a CJK character), marking the
chunk task GRAPH_EXTRACT_FAILED and letting asynq replay the identical
doomed LLM call up to the retry limit.

Classify responses that contain no JSON structure at all (no '{' or '[')
as errModelDeclined and complete the extraction with an empty graph so the
task succeeds as an explicit skip. Malformed or truncated JSON (structure
present) still fails and retries as before.

Fixes #3600

* fix(chat_pipeline): keep empty model responses retriable in graph extraction

An empty response is usually transient (gateway returning 200 with no
content, a reasoning model spending its whole budget on reasoning,
content filtering), and a retry often succeeds. Only non-empty prose
with no JSON structure is treated as a declined extraction.

* fix(graph): skip prose refusals only in the async chunk task, keep truncation retriable

ParseGraph no longer turns a prose answer into an empty graph. It returns
an error wrapping ErrModelDeclined, and ChunkExtractService.Handle is the
only caller that treats it as a skip (span output skipped=model_declined).
The /initialization "try extract" endpoint and query-side entity extraction
report the refusal as a failure again, so the graph settings form no longer
gets its few-shot examples replaced with an empty result.

Extractor.Extract drops the ErrModelDeclined marker when finish_reason is
"length": prose with no JSON because the output budget ran out is
truncation, and asynq should retry it.

* fix(graph): retry every truncation spelling, not only finish_reason=length

Extract kept a prose answer retriable only when FinishReason was exactly
"length". max_tokens / max_output_tokens (and case/space variants that
IsLengthFinishReason already accepts), a stream that broke before the stop
event ("incomplete") and an adapter that reports no reason were still read
as a refusal, so the async chunk task skipped the chunk for good.

Only a reason that proves the model stopped on its own now counts as a
refusal. Ollama's non-streaming Chat also forwards done_reason, so a
num_predict cut-off is reported as "length" instead of an empty string.

* fix(graph): only treat a response with no JSON anywhere as a refusal

The refusal check looked at the first extracted fence, so a prose fence
followed by a JSON fence was skipped as a refusal instead of failing as a
retriable parse error.

---------

Co-authored-by: LuckVd <LuckVd@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 14:57:11 +08:00
5quan 3fb6b9d631
fix(kb): let the update API set vlm_config (#3704)
* fix(kb): let update API set vlm_config

UpdateKnowledgeBaseRequest only carried name/description/config, so the
PUT /knowledge-bases/:id endpoint could never change a knowledge base's
multimodal (VLM) config, even though CreateKnowledgeBase accepts a
top-level vlm_config. Thread an optional vlm_config through the handler
and service so the update path mirrors create (nil = no change).

Fixes #1723

* test(kb): pass the vlm_config argument in tests added on main

* fix(kb): accept only model-managed vlm_config fields on update

The update API copied the request's VLMConfig wholesale, so a caller
could set the legacy ModelName/BaseURL/APIKey/InterfaceType fields and
have the VLM client call BaseURL directly, outside model management and
its SSRF checks. Only Enabled/ModelID/DescriptionLanguage/
CustomInstructions are taken now; legacy fields keep their stored value.
A referenced model must exist and be a VLLM model (400 otherwise), and
disabling clears ModelID, matching the initialization config endpoint.

* fix(kb): validate and gate vlm_config on the update API

- Enforce the 4000-character custom_instructions cap
  (types.ValidateKnowledgeBasePromptInstructions), as create and
  /initialization/config already do.
- vlm_config is a KB setting: require kbSettingsAccess (owner workspace
  or admin share) like /initialization/config, so share editors get 403.
- Stored legacy model_name/base_url keep IsEnabled() true on their own,
  so disabling returned 200 but left VLM on, and managed -> disabled fell
  back to the old endpoint. Clear them when the request enables a managed
  model_id, or disables VLM without echoing back the stored
  model_name+base_url (GET-then-PUT keeps legacy on). Request legacy
  fields are only compared, never written. Enabling without model_id on a
  non-legacy KB is now a 400 instead of a silent no-op.
- Document the vlm_config semantics in the KB API reference.

* fix(kb): keep the legacy VLM endpoint only for pure legacy knowledge bases

CreateKnowledgeBase stores vlm_config as sent, so a managed model_id can
sit next to legacy model_name/base_url; resolveVLM then uses the managed
model. The update's keep-legacy paths (disable echoing the stored legacy
fields, enabled=true without model_id) cleared model_id but kept the
legacy fields, so IsEnabled() stayed true and image calls moved to the
stored base_url.

Those paths now apply only when no model_id is stored. On a mixed config
a disable clears everything, and enabled=true without model_id is a 400,
the same as on any managed knowledge base.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 14:37:23 +08:00
Jin cbfd66fd92
fix(knowledge): delete written chunks when the storage quota check fails (#3656)
* fix(knowledge): delete written chunks when the storage quota check fails

processChunks writes the chunks before the storage quota check. When the
check fails, or the tenant cannot be re-read for it, the knowledge is marked
failed and the function returned without removing those chunks, so they
stayed active (deleted_at IS NULL, is_enabled = true) under a failed,
disabled knowledge. The BatchIndex failure path already deletes them; do the
same in both quota branches. Nothing has been indexed at that point, so only
the chunk rows need removing.

Fixes #3648

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* style(knowledge): keep the processChunks doc comment on processChunks

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:14:10 +08:00
linus-liu-web 4eb23a8560
fix(qdrant): CopyIndices 用服务端返回的 next_page_offset 翻页,不再按页尾 id 回填 (#3882)
* fix(qdrant): 复制索引改用服务端返回的游标,重复游标报错并给分页加跳数上限

CopyIndices 用"上一页最后一个点的 id"当游标(repository.go:987)。Qdrant 的
scroll offset 是**包含**语义 —— proto 里写的是 "Start with this ID",实测下一页
正是从该 id 本身开始返回,所以每翻一页都会把上一页的最后一个点再读一次、再写一份
到目标库。服务端本来就把下一页该用的游标放在 ScrollResponse.next_page_offset
("Use this offset for the next query")里,而客户端只在 ScrollAndOffset() 中返回它,
本函数调用的 Scroll() 恰好把它丢掉了;终止条件也只能退化成"这一页比 64 短"。

在真实 Qdrant 1.19.1 上实测:150 个源 chunk 复制出 152 个目标点,chunk-63 与
chunk-126 各被复制两次(每个页边界一个),totalCopied 同步虚高。源库只要超过一页
(>64 个 chunk)就会命中,不需要服务端有任何异常行为。

本次修改:

- 改用 q.client.ScrollAndOffset,游标直接取服务端返回的 next_page_offset;终止
  条件改为"服务端没有下一页"(next_page_offset == nil),不再用短页推断读完。
- 记录用过的游标,重复即返回 "copy indices made no progress at cursor ...",
  检测点在整页处理之前,重复的那一页不会再多写一份。
- 分页跳数上限 maxCopyPaginationHops(10000 页);触顶打印 Warn 并返回错误,
  而不是把这一轮复制当成成功。
- 修复后同一份数据在真实 Qdrant 上测得 150 个目标点、0 重复。

回归用例用假 gRPC 服务端(拦截 unary RPC,对齐 repository_test.go 的
newInterceptedQdrantClient)复刻真实服务端的游标语义:150 个源 chunk 必须各复制
一次(修复前 152 个点、2 个重复);游标恒定不动的源端必须报 no progress
(修复前 5 秒写入 3127040 个点仍未返回);一直推进但永不结束的源端在第 10000 页
被拦下。

* fix(qdrant): drop the CopyIndices page cap

10000 pages of 64 points capped a copy at 640k points and failed the
whole clone beyond that. The scroll walks every point of the source
knowledge base (a single-knowledge clone included), so a cap derived from
the chunk map would cut off small clones out of large bases too.
next_page_offset only moves forward, so the repeated-cursor check already
stops a walk that cannot finish, and the task context bounds the rest.

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:04:43 +08:00
Fei.Chen b8d83eab1c
fix(skills): skip vendored dep trees in install verification script enumeration (#3943)
* fix(skills): skip vendored dep trees in install verification script enumeration

sortedScriptPaths fed every .py/.js/.sh in the bundle into one shell 'for
f in ...' command. A skill that vendors a scientific venv (pandas/scipy/
matplotlib etc.) carries thousands of .py files under .venv/, and the
generated command exceeds the exec single-argument limit (MAX_ARG_STRLEN,
128KiB): /bin/sh fails with 'argument list too long' (exit 255) before
any check runs, so no dependency-heavy skill can ever install.

Vendored trees are installed dependencies, not scripts the model can
name; their health is already covered by the dependency verification
passes. Skip .venv/ and node_modules/ prefixes in sortedScriptPaths,
which fixes the tree check, the per-language parse passes and the
runtime prerequisite pass at once.

Verified by installing a 4862-file / 105MB quant skill (pandas+numpy+
scipy+statsmodels+matplotlib venv, real interpreter binary instead of
symlinks since zips cannot carry them): install failed before the fix,
reaches ready after it.

* fix(skills): skip vendored trees at any depth, not only at the bundle root

Bundles are author-zipped, so tools/.venv/ or sub/package/node_modules/
are as legal as root-level trees and enumerated just the same. The
filter now matches vendored trees under any prefix; nested placements
are covered by a regression test.

---------

Co-authored-by: vicfei <vicfei@users.noreply.github.com>
2026-10-08 01:28:45 +08:00
linus-liu-web 626185a120
fix(wiki): 重建链接逐页写失败不再静默,半成品不再回 200 (#3884)
RebuildLinks 的保存循环把每页 UpdateMeta 的失败降级成一条 Warn,函数最后
无条件 return nil,于是 handler 里既有的 err != nil 分支永远进不去:任意
一页写失败(行锁等待、死锁、连接中断、超时)时调用方仍拿到
200 "Links rebuilt successfully",而这些页面的 in_links/out_links 保持旧
值,反向链接与图谱继续显示过期关系,且没有任何途径知道"只重建了一部分"。

保持尽力而为的语义不变(一页失败不影响其余页面继续写入),但把失败页聚合
起来在结尾返回,沿用同仓库 knowledge_delete.go / wiki_ingest.go 的
errors.Join 写法,以及同文件 MovePage 对同一个 UpdateMeta 调用的报错写法。
handler 无需改动:其既有 500 分支会如实返回 "N of M pages failed" 与失败页
slug。

回归用例用 SQLite 触发器让指定页的 UPDATE 真的报错(不是 mock),走真实仓库
与真实 handler:
- 部分失败:RebuildLinks 返回聚合错误,可写页仍被刷新,失败页保持旧值;
- 全部失败:错误里含 3 of 3 与全部 slug;
- HTTP 层:部分失败回 500 且错误体含失败页与底层原因,全部成功才回 200。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:25:53 +08:00
xxxxx 4d7e663128
fix(wiki): preserve pending work when source lookups fail (#3715)
* fix(wiki): preserve pending work when source lookups fail

* test(weaviate): snapshot schema state before probe barrier
2026-10-08 01:25:45 +08:00
sun fac9ebabf2
fix(knowledge): close spans left open on terminal rows and superseded attempts (#3855)
Sweep A only selects pending/processing/finalizing, so a row that reaches a
terminal state while its attempt is still open is never revisited: its spans
stay "running" and the document timeline shows a permanent 进行中. Found in
production with four root spans stuck for 11 and 27 days.

- housekeeping: add Sweep D (reapTerminalSpans) closing spans still open on
  terminal rows, carrying the row own error_message so the timeline still
  names the real cause. A self-healing backstop for every failure path that
  forgets to close its attempt, including rows stranded by older releases.
- span tracker: OpenAttempt now cancels spans left open by earlier attempts
  (ATTEMPT_SUPERSEDED). A reparse used to open its new root alongside the
  previous attempt dead root, which is what made historical runs look
  like they had been reactivated.

Co-authored-by: asmh1989 <minhua.sun@velavigo.com>
2026-10-08 01:25:38 +08:00
诉说晚秋 95691daab2
fix(knowledge): retry document processing after transient indexing failures (#3915)
processChunks marked the knowledge failed and returned nil when BatchIndex
failed, so ProcessDocument acked the task and the configured document-task
retries never ran. A short embedding or vector-store outage left the row
permanently failed; unchanged data-source syncs did not reprocess it.

While attempts remain, still clean up the partial chunks and vectors but
keep the row processing and return the error to the queue. The final
attempt (or a caller without a retry loop) records the failure as before.
2026-10-08 01:25:31 +08:00
linus-liu-web a15dfdd941
fix(summary): 坏 JSON 不再冒充文档摘要(截断/畸形 JSON 走失败路径,纯文本兜底保留) (#3769)
* fix(summary): 坏 JSON 不再冒充文档摘要

非流式文档摘要(Chat)解析失败时原先把模型原文当摘要落库:被 MaxTokens
截断的半截 JSON 会写进 knowledges.description、置 SummaryStatus=Completed
(Asynq 不再重试),同一段文本还会被 buildSummaryChunkContent 索引进 RAG。

- parseDocumentSummaryOutput 改为返回 (*documentSummaryResult, error):
  回复形如 JSON(含 markdown 代码围栏)却解析失败、或解析成功但取不到
  summary/gist 时返回 errSummaryOutputNotParsable,绝不回退成原文;
  非 JSON 的纯文本仍走原有的原文兜底,自定义模板 / 老模型不受影响。
- validateSummaryOutput 复用 chatpipeline.IsLengthFinishReason,
  FinishReason 为 length 类取值时返回 errSummaryOutputTruncated。
- 两个 sentinel 经 getSummary 汇入既有失败路径(ProcessSummaryGeneration
  的 handleRetryableSummaryFailure、RegenerateKnowledgeSummary 的
  handleGenerationFailure):保留旧描述、置 pending/failed 交给 Asynq 重试,
  不再以 Completed 落库。

测试:TestParseDocumentSummaryOutput 改为表驱动(截断 JSON、含裸换行 JSON、
无文本 JSON 必须报错且不能把原文当 Summary;纯文本兜底继续通过);
TestValidateSummaryOutput 增加 length / max_tokens 截断用例;
TestGetSummaryRejectsUnusableModelOutput 锁住 getSummary 的错误传播。

* fix(summary): length 截断判定收窄到 JSON 形状回复

非流式文档摘要在校验模型回复时先看 finish_reason:只要 provider 报告
length/max_tokens 就返回 errSummaryOutputTruncated。该判定不认识内容形状,
于是自定义纯文本模板一旦顶到输出预算,就从「截断但可用」变成重试直到
SummaryStatusFailed,与上一提交承诺的「非 JSON 的纯文本仍走原兜底」相反。

- validateSummaryOutput 恢复为只看内容是否为空;新增
  validateStructuredSummaryDocument 供 getSummary 使用:先判形状再判
  length,只有确实在产结构化摘要(能解析成对象/数组,或 { 开头、[ 开头接
  对象/数组/字符串元素)且被预算截断时才返回 errSummaryOutputTruncated。
- 形状判定剥离 UTF-8 BOM、前后空白与一层 markdown 围栏后再尝试
  json.Unmarshal;「[文档摘要] …」「[1] …」这类带方括号引用的纯文本不再被
  误判成坏 JSON,而截断的 {summary: 与截断的 JSON 数组仍然报错。
- parseDocumentSummaryOutput 同步剥离 BOM:BOM 前缀的截断 JSON 之前会被
  当成纯文本落库。
- 表格描述 / 列描述仍走 validateSummaryOutput,截断的描述照旧可索引。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-08 01:21:01 +08:00
Ankit Jha 27b9ee74a0
fix(storage): use virtual-hosted addressing for Tencent COS through the S3 driver (#3722)
newS3Client forced path-style for every non-AWS endpoint, so a COS
endpoint such as https://cos.ap-shanghai.myqcloud.com sent requests to
cos.<region>.myqcloud.com/<bucket>/<key>. COS rejects path-style for
buckets created from 2024-01-01, so STORAGE_TYPE=s3 could not reach new
COS buckets, and force_path_style=false had no way to turn it off.

Treat *.myqcloud.com like AWS and use virtual-hosted style. An explicit
force_path_style still wins, and other S3-compatible endpoints keep
path-style.

Fixes #3134

Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
2026-10-08 01:20:54 +08:00
诉说晚秋 7c284e7fc9
fix(faq): 保留克隆状态同步时的正文和索引状态 (#3993) 2026-10-08 01:20:39 +08:00
knqiufan e29301115a
fix(graph): preserve relationship direction and document provenance (#3950)
* fix(graph): preserve direction and document provenance in graph retrieval

* test(graph): verify live query bounds and seed evidence ordering

* fix(graph): deduplicate expansion using bounded seed identities

* ci: retry upstream scan after missing CodeCC report
2026-10-08 00:48:51 +08:00
AI即世界 afc6cbd502
fix(milvus): validate connections and preserve gRPC resolver defaults (#3654)
* fix(docreader): preserve gRPC resolver defaults

* fix(milvus): validate connection with SDK handshake

* fix(docparser): preserve gRPC resolver defaults

* fix(milvus): satisfy connection check lint

---------

Co-authored-by: tunan <tunan@ahyk.com>
2026-10-08 00:48:45 +08:00
Mohamed Arbi 9fa9e7c29d
fix: use consistent qdrant env settings (#3960)
* fix qdrant env settings

* fix test formatting
2026-10-07 23:59:56 +08:00
linus-liu-web 5648d24a93
fix(retriever/milvus): CopyIndices 按映射分块读源行,去掉会静默漏向量的 offset 窗口 (#3883)
CopyIndices 用 offset/limit 窗口遍历源知识库:offset 是"跨请求保持不变的结果
顺序"上的游标,而普通 query 不承诺这个顺序(结果按 segment 合并,且本次拷贝
每页都在往同一个 collection 写目标行),窗口一漂移就会跳过落在新窗口之前的行、
并重读被窗口退回的行;终止条件"短页即结束"(count < batchSize)又把因此提前
出现的短页当成读完了,剩余向量被静默丢掉,函数仍然返回 nil。用进程内假 Milvus
(gRPC 服务 + DisableConn,走真实 client.Query/Upsert 路径)在每次写入被确认后
旋转结果顺序复现:200 个源 chunk 全部返回成功、日志 total copied: 200,但
3 个 chunk 的向量从未写入目标库、另有 3 个被写了两遍(offsets=[0 64 128 192])。

改成按映射里的源 chunk ID 分块读:谓词 = knowledge_base_id 相等 + chunk_id in
(本批 64 个),读到的行集合由谓词唯一确定,没有游标可漂。拷贝的集合与改动前一致
(原先读到但不在映射里的行本来也会被跳过),只是不再按 offset 前进。同一文件的
chunk_id 批量读(updateChunkEnabledStatusInCollection、BatchUpdateChunkTagID)与
SQLite 版 CopyIndices 用的就是这个形状。

回归用例用进程内假 gRPC Milvus 注入跨页顺序漂移:去掉本修复该用例必失败
(missing=[target-chunk-064 target-chunk-129 target-chunk-194]、
repeated=[target-chunk-000 target-chunk-001 target-chunk-002] 而函数返回 nil),
修复后 offsets 全为 0、无缺失无重复。

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:44 +08:00
linus-liu-web 5f5093b9f7
fix(retriever): Qdrant/Milvus 关键词检索整批失败返回 error,不再当成「没有匹配」 (#3847)
* fix(retriever): Qdrant/Milvus 关键词检索整批失败不再当成没有匹配

Qdrant 与 Milvus 的 KeywordsRetrieve 逐个 collection 检索,单个 collection 失败只降级成
一条日志后 continue。循环结束后按结果条数分支:全部 collection 失败与确实零命中都会打印
"No keyword matches found"、返回空结果与 nil error。上层只看第二个返回值,据此判定知识库
没有相关内容,用户与模型都无法区分"没有这个词"和"检索没有执行成功"。

改为在循环内累计匹配到的 collection 数与失败的 collection 数,全部匹配 collection 都失败
时返回带底层原因的聚合 error,例如
"qdrant keyword search failed in all 2 matched collections: <cause>"。计数放在 collection
名前缀/维度匹配之后,名字不匹配的 collection 不参与统计;匹配到的 collection 为 0 时维持
原行为,不报错。Milvus 的三处 continue(Search / convertResultSet /
buildMilvusIndexResults)全部计入,另有两处同样会跳过 collection 的失败路径(analyzer mode
探测、过滤器构建)一并计入,这三处的日志补上 collection 名。

部分失败时不再打印结论性的 "No keyword matches found":有结果时改为提示结果不完整,无结果
时说明有多少个 collection 应答过、多少个失败;只有本次调用没有发生任何错误时才继续打印该
结论。RetrieveResult.Error 保持原样(仓库内没有读取方),改动面最小、语义最清晰的暴露方式
是整批失败返回 error。

回归测试:
- Qdrant(repository_test.go):假 Qdrant gRPC 服务让 Scroll 全失败时返回 error 且不打印
  结论日志;只有一个 collection 失败时结果与 nil error 不变;全部成功且零命中时仍返回空结果
  + nil error 并保留结论日志。
- Milvus(新增 keywords_test.go):*client.Client 没有接口缝隙,改用进程内 Milvus gRPC 假
  服务(ShowCollections / DescribeCollection / Search)覆盖同样三种情形,走真实 Search 与
  结果转换路径。
- go.mod:milvus-proto 由新测试直接导入,去掉该依赖的 // indirect 标记。

反向验证:把两个 repository.go 改回原样后,两条"全部失败"用例分别以
"all-collections failure must surface as an error, got <nil>" 与
"An error is expected but got nil" 失败,部分失败与零命中两条用例保持通过;随后逐字节还原
修复。

* fix(retriever): 关键词检索部分失败随结果一起暴露,不再被当成完整结果

Qdrant/Milvus 的 KeywordsRetrieve 逐 collection 检索,部分 collection 失败时保留其余
collection 的结果并返回 nil error。上层拿到的是"结果 + nil error":既不知道少了几个
collection 的内容,也没有任何读取方,RetrieveResult.Error 因此长期是死字段。上一个
commit 只处理了"全部匹配 collection 都失败",部分失败仍然静默降级,模型与用户看到的
都是不完整结果。

让部分失败沿着结果走完这条链路:

- repository(qdrant/milvus):部分失败时把
  "… keyword search failed in N of M matched collections: <cause>" 写进
  RetrieveResult.Error —— 结果照常返回、调用级 error 仍为 nil;全部失败仍是调用级
  error,真正的零命中仍然 Error == nil;
- CompositeRetrieveEngine:读取每个结果集的 Error 并聚合,连同结果一起返回
  ("retrieve returned partial results: …");引擎级 error 仍然丢弃全部结果,
  all-or-nothing 策略不变;
- retrieveFromStores(该接口的唯一消费方):结果与 error 同时非空即"部分失败",打出
  带 store group 与原因的 WARN 并保留结果返回 —— 既不会把降级 store 升级成整次搜索
  失败,也不会让上层把不完整结果当完整结果;
- matched == 0(没有任何 collection 匹配 base name)单独打一条 Warn,与"检索成功但
  零命中"区分开;
- milvus/repository.go 的 allFields 块按 gofumpt 重排,四个包 gofumpt -l 干净。

回归测试:

- qdrant/milvus:部分失败(有命中 / 零命中)结果集带 Error 且调用 error 为 nil;全部
  成功零命中仍 Error == nil 且保留结论日志;全部失败仍是 error;matched == 0 打专属
  Warn 且不发任何 Scroll/Search;
- CompositeRetrieveEngine:结果集带 Error → (结果, error) 同时返回;结果集完整(含零
  命中)→ 无 error;引擎级 error → 丢弃全部结果;
- retrieveFromStores:单 store / 多 store 部分失败都打 WARN 且保留结果,完整零命中不
  打 partial 日志,引擎级 error 仍然失败。

反向验证:去掉四个源文件的可见性改动后,17 条新/改用例中 9 条失败(qdrant 3、milvus 3、
composite 1、retrieveFromStores 2),钉住"行为不变"的 8 条保持通过;还原后 diff 与
改动前逐字节一致。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:38 +08:00
linus-liu-web f9eeb8dc85
fix(retriever/es): _bulk 的 per-item 失败不再被吞,全部被拒时 BatchSave 返回错误 (#3842)
Elasticsearch 受理 _bulk 请求即返回 HTTP 200,单个文档的写入失败只体现在响应体的
errors 与 items[].<op>.error。v8 把响应对象整个丢弃,只看传输层错误;v7 读了响应,
却只把结论降级成一行告警,响应体解析失败同样返回 nil。两个驱动的 BatchSave 因此在
文档被逐条拒绝时仍返回成功:调用方不标记 failed、不清理 chunks,阶段数据照写全部
条数,文档从此搜不到也不会重试。触发条件都是常规运维事件——mapping 不符、磁盘水位
只读、index 缺失、写压力下的 item 级拒绝。

修复:
- v8 接收 typed bulk 响应对象,resp.Errors 为真时遍历 resp.Items 聚合失败项。
- v7 把 countBulkErrors 的结论从"仅告警"升级为返回错误;响应体解析失败同样返回
  错误,不再把结果未知当成成功。
- 错误信息只带文档 _id 与有界的 error.type,最多摘要 5 条,失败条数覆盖全部失败
  项;error.reason 可能含文档正文,只写 debug 日志。写法对齐 OpenSearch 驱动既有
  的 inspectBulkResponse。

回归测试(v7/v8 各一份,httptest 假 ES + 真实构造函数):全部被拒返回错误、部分
失败返回错误且能看出失败条数、全部成功返回 nil;v7 另覆盖响应体损坏。断言同时确认
返回的错误不含 error.reason 中的文档内容。

反向验证:把两个驱动改回原实现后,新增用例 v7 失败 3 条、v8 失败 2 条;恢复修复后
全部通过。

Fixes #3832

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:32 +08:00
linus-liu-web a8a2c17b89
fix(sqlite): 索引行写入失败不再被丢弃,BatchSave 回滚而不是留下「主行在、索引行不在」 (#3843)
* fix(sqlite): 索引行写入失败让 Save/BatchSave 报错并回滚

Lite(DB_DRIVER=sqlite)的 vec0 / FTS 索引行 helper 丢弃 Exec 返回值:
BatchSave 的事务末尾无条件 return nil,于是 chunk 主行提交而索引行缺失,
Save/BatchSave 仍报成功,向量与关键词两条检索路径都静默漏召回;CopyIndices
的 copyVec 同样可能报成功而向量行没有复制过去。

- insertVec / syncFTS5Insert / copyVec / deleteRowsAndVecs 返回 error,在
  BatchSave(事务内)与 CopyIndices 的调用点检查并上抛:事务回滚,
  BatchIndex 报错后走 knowledge_process.go 既有的清理与 failed 标记路径;
  删除路径在索引行删除失败时不再删除主行。
- ensureVecTable 校验同名对象确实是 vec0 表之后才缓存"已就绪",失败上抛
  (BatchSave 与 vectorRetrieve);向量写失败时清掉该维度的缓存,下一次写入
  重新建表,而不是被永久短路。
- initFTS5 返回 error,并把建表与回填放进同一个事务(半回填的索引会静默丢
  召回);驱动未编译 fts5 模块(上游 go test 不带 -tags sqlite_fts5)时只
  记录一次并跳过关键词写入,而不是让每次入库失败;Lite 发布构建始终带该 tag。

新增 index_write_errors_test.go:覆盖 vec0 / FTS 表缺失、vec0 维度不匹配、
同名对象占位、索引删除失败、CopyIndices 向量复制失败,以及正常路径与无 fts5
模块构建。把修复改回原样后,其中 6 个用例必失败。

Fixes #3833

* fix(sqlite): CopyIndices 行复制失败累计上报,不再 Warn 后跳过

克隆/搬运知识库时逐行 Create 失败原先只记 Warn 并 continue:目标库会缺
主行/索引行却仍报成功。现改为逐行累计错误,FTS 与向量复制失败同样累计
而不是遇到第一条就返回,最后 errors.Join 交给调用方;错误里带源/目标
chunk id 便于定位失败行,不含正文。调用方沿用既有 rollbackIndices 回滚
与 failed 标记路径。

新增回归用例:触发器拒单行 -> 调用方拿到可定位到该行的错误、同 chunk 的
其它行照常复制;DROP FTS 表 -> 错误带上表和 chunk id 且向量行仍写入。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:26 +08:00
linus-liu-web 72b8a106c7
fix(sqlite): 检索后端批量更新索引副本失败不再吞掉错误 (#3768)
* fix(sqlite): 检索后端批量更新索引副本失败不再吞掉错误

Lite(DB_DRIVER=sqlite)的 BatchUpdateChunkEnabledStatus 与
BatchUpdateChunkTagID 逐条执行 Update 后丢弃 gorm 的 .Error 并无条件
return nil:索引副本更新失败被吞,接口仍报成功。

服务层是"先写权威 chunks 行(成功)→ 再同步检索索引副本"
(knowledge_faq.go:877-889 等),而检索只读索引副本
(lite_embeddings.is_enabled / tag_id)。因此索引 UPDATE 失败
(SQLITE_BUSY、磁盘满)或未命中任何行时,接口返回成功、UI 显示新标签
或已停用,但按新标签过滤搜不到、刚停用的条目仍会被召回。postgres 后端
同名函数在 result.Error != nil 时本就 return result.Error,sqlite 与之
对齐:逐条检查 .Error,非 nil 时用 fmt.Errorf 包装 chunkID 与操作名
返回。postgres 不把 0 行当错误(仅记录 RowsAffected 日志),故此处也
不引入"0 行即错误"。

新增 batch_update_test.go:用 DROP TABLE 与触发器构造必然失败的
UPDATE,断言返回非 nil 错误(修复前返回 nil),并覆盖成功路径。

注:本条是 sqlite 后端"执行了但吞掉错误",与 #3426 的 weaviate 后端
"未真正执行操作"属于不同后端的不同机制。

* fix(sqlite): 批量更新索引副本累计错误后汇总返回,并让 0 行可见

BatchUpdateChunkEnabledStatus / BatchUpdateChunkTagID 逐条执行 UPDATE,上一版
改成"首个错误即 return":语义从"尽力更新全部"退化成"只更新一个前缀",而前缀
取决于 map 迭代顺序。同类后端不是这么做的:milvus 与 qdrant 都是把每条错误
累计进切片后 errors.Join 并继续跑完。因此改为循环内累计错误、跑完全部行,最后
errors.Join 返回;错误信息仍带 chunkID 与操作名,调用方观察到的"失败即 error"
不变。

另外上一版只检查 .Error,没有看 RowsAffected:"索引 UPDATE 匹配 0 行"在
sqlite 上依然完全不可见。0 行仍不算错误(索引副本允许落后于权威 chunks 行,
postgres 后端同样只记日志),但现在会打一条 Warn,带表名、列名与 chunk_id,
不含正文内容。

测试(internal/application/repository/retriever/sqlite/batch_update_test.go):
- ReportsEveryFailingStatementInBatch:触发器让批内 5 条全部失败,断言
  errors.Join 中 5 个 chunk 都出现、失败消息出现 5 次。首错即 return 时只有
  1 条,用例必失败。
- KeepsUpdatingAfterStatementFailure:批内 chunk-3 失败时 chunk-4/5 仍被更新;
  断言落在结果行而非"第几条",因为 map 迭代顺序随机。
- WarnsWhenStatementMatchesNoRow:命中 0 行仍成功返回,但日志里有带
  lite_embeddings.<列名> 与 chunk_id 的 Warn。

顺带补 gofumpt 要求的函数间空行(main 上既有的格式差异),使该文件 gofumpt 干净。
默认构建与 -tags sqlite_fts5 两种构建下
go test ./internal/application/repository/retriever/sqlite/... -count=1 均通过。

---------

Co-authored-by: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com>
2026-10-07 23:59:19 +08:00
hailongzhao bccb4b151b fix(embed): 内嵌网页只传图片不输入文字时不再返回 400
内嵌网页的输入框允许只带图片或附件就点击发送,但 CreateKnowledgeQARequest.Query
带有 binding:"required",parseQARequest 也拒绝空 query,于是只传图片直接返回
400 "Query content cannot be empty"。

入口处理:去掉 binding:"required";文字为空但带有内联图片数据或内联附件时,
用 types.UploadOnlyQuestion 生成一句替用户提问的问题(中文界面为「请根据我
上传的内容回答。」,其他语言为英文),交给模型、检索、标题、会话历史索引、
追问建议和记忆使用。只有 URL 的图片不算上传,因为客户端传入的图片 URL 会被
清掉;预上传的 attachment_ids 也不算,这类文件在流开始后才解析,可能失败或
超时,届时模型没有任何内容可答。其余空 query 仍返回 400。

存储与显示:qaRequestContext 新增 userInput,保存用户消息时只存用户实际
输入,只传图片时为空,刷新后与发送当下显示一致;query 仍是给模型的问题。
steer 追问复制上一轮的请求上下文,显式设置 userInput,避免在只传图片的一轮
之后把追问存成空消息。

会话历史:文字为空但带图片或附件的用户消息,在两处历史重建里补上同一句
问题。知识问答流水线(loadAndProcessHistory)原先会整轮丢弃;Agent 历史
(LoadAgentHistory)原先会发出空的用户消息,被 SanitizeMessages 剔除后
前后两条回答被合并。

去掉 binding 标签会让 gofmt 重新对齐整个 CreateKnowledgeQARequest 的行尾
注释,这些既有的超长行因此会被 PR 的增量 lint 视为新增。按仓库惯例把字段
注释移到字段上一行(注释文字不变,swagger 描述不受影响),并把 Go 字段
KnowledgeIds 改名为 KnowledgeIDs(JSON 名仍是 knowledge_ids,接口不变)。

同步更新 swagger 文档,query 不再是必填字段。
2026-09-30 15:26:51 +08:00
linus-liu-web 2ec1774623 fix(auth): 令牌写入失败不再当成登录成功,查询失败不再谎称已撤销
generateTokensForTenant 把两次 CreateToken 的错误都丢给了 `_`,然后照常返回
token 对。签发出去的 JWT 签名正确、语法合法,但 auth_tokens 里没有行,
ValidateToken / RefreshToken 在下一次请求就把它拒掉——用户看到的是"刚登录就掉
线,反复登录都一样"。更糟的是校验侧把"查不到"和"已撤销"合并成同一个分支:

    if err != nil || tokenRecord == nil || tokenRecord.IsRevoked {
        return nil, 0, errors.New("token is revoked")
    }

于是真实的插入错误既没有落日志,也被贴上了一个从未发生过的原因("token is
revoked"),把排查方向引向"会话被踢"。触发条件只是常规基础设施抖动:语句超时、
连接池耗尽、连接被重置。

同文件的对照写得很清楚:SwitchTenant 对同类写入 `return fmt.Errorf(...)`("a
200 response is also a durable landing-preference update"),Logout 直接返回
RevokeTokensByUserID 的错误;这两处是全文件唯一"写完不检查"的地方。

改动:
- 两次 CreateToken 都检查错误,失败即 `persist access token/refresh token: %w`
  返回,保证"登录成功"一定对应已持久化。正常路径不变:两行都写成功才返回令牌对。
- ValidateToken / RefreshToken 把查询错误与"已撤销/不存在"拆开:查询失败按基础
  设施错误上报(`look up token: %w`),`IsRevoked` 仍然报 "token is revoked",
  不再用一句假话掩盖查询失败。

新增用例(internal/application/service/user_token_persistence_test.go):
- 写入失败时 Login 必须 Success=false 且不下发任何令牌;
- 访问令牌/刷新令牌任一写入失败都不得返回令牌;
- 正常路径回归:两行都落库、access token 随后能通过 ValidateToken;
- 查询失败如实上报(errors.Is 命中原始错误,且不含 "token is revoked");
- 真的被撤销时 "token is revoked" 仍然保留。

L2 复现(假 token repo 返回写失败):修复前 Login 返回 success=true、
tokenIssued=true,紧接着用该 token 请求得到 "token is revoked";修复后 Login
返回 success=false、message="Login failed"、不下发令牌。去掉 user.go 的改动后
新增用例 5 个子用例全红,两条正常路径回归用例仍绿。整个 service 包
`go test ./internal/application/service/` 通过,scoped golangci-lint 0 issues。
2026-09-30 13:40:51 +08:00
lyingbug 5225edc0f7
feat(auth): 新增仅限邀请注册档位 (#3900)
* feat(auth): add invitation registration mode

* fix(auth): resolve registration mode lint errors
2026-09-30 13:32:55 +08:00
LL_Ricky 9842e51d40
fix(frontend): 修复复制模型时模型名称被改写的问题 (#3830)
* fix(frontend): 修复复制模型时模型名称被改写的问题

* fix(model): preserve model name and credentials when copying a config

Copying rewrote the upstream model name and posted redacted parameters, so the duplicate could not authenticate. Clone the stored row, cap the display name, and skip a new download when the local model is already active.

* fix(lint): clear new golangci-lint findings on model copy

Check c.Error results, wrap the long test line, and format the stub. The pull request lint range also includes the new HTTP error test, whose unused request parameter failed revive.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-29 19:32:08 +08:00
hailongzhao f46c990567 fix(embed): 开启 Host context 后点击追问建议不再返回 400
嵌入渠道调用 WeKnora.setContext 后,前端 buildQueryWithHostContext 会把
query 包成 "[Host context]\n<k: v 行>\n\n<问题>" 再发出,而
ValidateAttribution 用 TrimSpace 后的全文与建议文本做精确比较,带信封的
query 永远不相等,于是每次点击追问建议都返回 400
"invalid suggestion attribution"。

后端:新增 queryMatchesSuggestionText,精确匹配失败时识别 host context
信封——要求以 "[Host context]\n" 开头、信封内容非空、以空行结束,且空行后
紧跟的正好是被点击的建议文本。宿主传入的 value 可以含换行甚至空行,所以用
建议文本从尾部锚定切分,而不是取第一个 "\n\n"。不校验信封里每行的 key/value
形态:前端对 key 不做约束(带空格、空 key、value 以换行开头都会原样拼进去),
校验只会误伤合法 context,而归因只用于统计点击与实际发送,不涉及权限。
在信封与问题之间或问题之后夹带额外文本、任意前缀、空信封仍会被拒绝。

前端:handleFollowUpSelect 原先在回复生成中点击建议时也会写入待发送归因,
但跳过发送,归因会泄漏到用户下一条手动输入的消息上,同样导致 400。改为只在
真正发送时写入归因,click 事件照常上报。

Fixes #3820
2026-09-29 12:16:46 +08:00
linus-liu-web 1912ba26c5 test(weaviate): 让并发建表的用例真的每个 worker 都去创建,消掉随机失败
TestEnsureCollectionToleratesConcurrentCreation 用 barrier 让 8 个 worker 都先探到
"class 不存在",再一起冲创建,最后断言 server.creates == workers。但假服务器的 GET
分支是「先等 barrier、再采样 s.exists」:barrier 一放开,赢家的 POST 可能已经把
exists 置为 true,排在后面的 worker 采样到"已存在",就在创建之前返回了,从来没去
尝试创建。实际创建数取决于调度(本地 100 次里挂 1 次;CI 上是 4 或 6),断言于是
随机失败 —— main 自己的 CI 与多个 PR 都挂在这条上。

把采样挪到 barrier 之前:每个 worker 读到的是它到达时的状态(此刻必然为 false),
8 个创建请求全部到达服务端,断言稳定。测试注释里写的意图本来就是"让每个 worker 都
看到 class 缺失",这里只是让实现与意图一致。

只改测试,不碰生产代码。
2026-09-29 01:32:23 +08:00
linus-liu-web e39043f34b fix(repository): 关键词 LIKE/ILIKE 检索补显式 ESCAPE,修复 Lite 上静默漏结果
SQLite(Lite 版所用数据库)没有默认的 LIKE 转义字符,而 Postgres 的默认转义字符是
反斜杠。escapeLikeKeyword / escapeLikePattern 会把关键词里的 %、_、\ 转义成 \%、\_,
但只有在 SQL 中显式声明 ESCAPE 时才有意义:缺少 ESCAPE 时 SQLite 会把反斜杠当成普通
字符,于是任何含 _ 或 % 的关键词(如 IMG_2534、100%)都匹配 0 行——不报错、不打日志,
total 同样为 0,前端只显示"暂无数据"。Postgres 因默认反斜杠转义而表现正常,所以问题
只在 Lite / SQLite 上静默出现。

本次修改统一在 LIKE 表达式后补 ESCAPE,并把 escape 字符作为参数传入(Postgres 的
ILIKE 分支同样处理),写法对齐 message.go / message_artifact.go / chunk_image_assets.go
中已有的正确站点,转义字符复用 knowledge.go 既有的 likeEscapeChar 常量。

修复站点:
- knowledge.go applyKnowledgeListFilter 文档列表关键词过滤
  (agent 工具 list_documents、mcp-server tools_retrieve 复用)
- knowledge.go SearchKnowledge
- knowledge.go SearchKnowledgeInScopes(GET /api/v1/knowledge/search)
- tag.go ListByKB 标签搜索(count 与 data 两条查询)
- tenant.go SearchTenants 租户搜索(带/不带 tenantID 两个分支)
- tenant_member.go CountFilteredByTenant / ListPagedByTenant 成员邮箱、用户名搜索
- session.go QueryPaged 会话列表/侧栏标题搜索(LOWER LIKE 与 Postgres ILIKE 分支)
- chunk.go ListPagedChunksByKnowledgeID 分块/FAQ 搜索

chunk.go 属反向错误:关键词完全没有转义,% 和 _ 被当作通配符导致多匹配。这里同样改为
escapeLikeKeyword + ESCAPE,而不是把别处的转义去掉——关键词里的 % 和 _ 是用户想按字面
匹配的字符(文档名 IMG_2534、进度 100% 都很常见),去掉转义会让它们又变成通配符、匹配
到无关结果;只有显式 ESCAPE 才能让 Postgres 与 SQLite 行为一致。

顺带把 escapeLikePattern 收敛为 escapeLikeKeyword 的薄封装(wiki_page.go 一处),
两者原本是逐字符等价的重复实现,调用点语义不变。转义字符常量仍复用 likeEscapeChar,
未新增常量。

新增 SQLite 回归测试 internal/application/repository/like_escape_sqlite_test.go,覆盖上述
全部站点:每个用例同时埋入"字面命中行"和"通配符诱饵行",缺 ESCAPE 会因 0 行失败,缺
转义会因多匹配失败。已逐站点反向验证:去掉 ESCAPE(或去掉 chunk.go 的转义)后测试确实
失败,随后逐字节还原。

注:organization.go ListSearchable 与 user.go SearchUsers 的关键词同样未转义,但它们是
Postgres 专用路径(ILIKE / ::text),属另一类问题,不在本次改动范围内。
2026-09-29 01:31:37 +08:00
Fei.Chen ec0ca46334
fix(server): run ResourceCleaner on signal shutdown instead of racing Fatalf exit (#3804)
* fix(server): signal shutdown raced Fatalf exit before ResourceCleaner ran

The signal goroutine closed the listener before calling server.Shutdown,
so Serve returned the raw accept error ('use of closed network connection')
instead of ErrServerClosed. The invoke error path then hit logger.Fatalf
(os.Exit(1)) in the same millisecond, killing the process before the
shutdown goroutine reached resourceCleaner.Cleanup. Every registered
cleaner — BrowserSkill daemon, sandbox reapers, IMService, AntsPool,
Langfuse — was skipped on every SIGTERM/SIGINT, leaking the shared bsk
daemon process and its temp home on each restart.

Two changes:
- Drop the manual listener.Close(): Shutdown closes all listeners as its
  first step, releasing the port just as fast without racing Serve.
- Give resourceCleaner.Cleanup its own fresh timeout context so a slow
  connection drain cannot leave Cleanup with an already-expired context,
  which made it skip every entry without running any.

* fix(server): keep signal cleanup inside one grace period

Desktop quit still closed the listener before Shutdown and returned
before ResourceCleaner finished, so Fatalf could skip every hook.
Share ShutdownTimeout between drain and cleanup, run BrowserSkill
first, and do not drop later hooks when the deadline expires.

* fix(server): satisfy errcheck and line-length lint

---------

Co-authored-by: vicfei <vicfei@users.noreply.github.com>
Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-28 23:37:36 +08:00
wizardchen c819abd958 fix(wiki): bound outstanding follow-up tasks 2026-09-28 22:02:07 +08:00
Duke 4ba85e2edf fix(wiki): fan out follow-up triggers so backlogs drain at ingest_max_inflight
Since Phase 3 the consumption side (disjoint claiming, per-slug locks,
the inflight cap) fully supports concurrent batches, but nothing created
more than one trigger per completed batch: once uploads stopped, a KB
with a standing backlog drained at 1 batch x batch-size per cycle
regardless of ingest_max_inflight, leaving the wiki pool and the model
server idle.

followUpTriggerCount now re-arms min(batches the remaining rows still
need, slots that could be free when the triggers fire). The caller's
own slot releases right after scheduleFollowUp returns, hence the +1.
activeInflightSlots is a read-mostly Lua companion to the reserve
script (purge expired, then ZCARD); -1 means unknown (no Redis / Redis
error) and collapses to a single follow-up, as do maxInflight <= 1 and
Lite mode (liteLocks serialize per KB anyway). Fan-out is deliberately
skipped on a rate-limited exit so a 429 storm is not amplified.

Over-issued triggers are harmless: the ones that cannot get a slot are
acked and coalesced by scheduleCappedRetry's fixed TaskID. The slot
count renders as "unknown" in the log when it was not consulted.
2026-09-28 22:02:07 +08:00
Perfecto 675b06addc test: consolidate table summary regressions 2026-09-28 21:24:02 +08:00
Perfecto d270a844ac fix: reject empty table-summary model responses 2026-09-28 21:24:02 +08:00
Perfecto d528d1fc3c fix: skip table-summary tasks for missing documents 2026-09-28 21:22:45 +08:00
Victor Maznyuk 0b463e459a test(skills): wait for the host install to release its lock before asserting
TestHostInstallActivatesVersionAndMarksReady waited for the row to reach
ready and then read the fake tree and installer. runHostInstall records
ready while it still holds the skill lock; pruning old versions, unbinding
the install session and unlocking come after, so the test could observe
tree.pruned as nil or installer.bound still populated, and the race
detector reported the unsynchronised reads.

The fake tree now counts runs between Lock and unlock, and the wait
helpers block until no run holds it. The run unlocks last, so everything
it wrote is visible once the wait returns. waitRemoveDone had the same
gap (the row is deleted before the stale marks are recorded) and uses the
same wait.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 21:07:04 +08:00
Victor Maznyuk 5bf2ae1cc2 fix(faq): actually clean FAQ entry payloads before validation and storage
sanitizeFAQEntryPayload called meta.Normalize() and discarded the result.
Normalize returns a normalized copy for hashing and indexing and does not
touch its receiver, so no cleaning happened: blank, whitespace-only and
duplicate similar/negative questions and answers were stored as sent, two
empty similar questions were reported as a duplicate, and answers: ["  "]
passed the "at least one answer" check.

Call meta.Sanitize(), the in-place method meant for storage (trim, drop
empties, de-duplicate, keep the original text).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 20:29:29 +08:00
linus-liu-web a570dffcfa test(wiki): 表格夹具改用合成数据
`certLedgerRow` / `certLedgerBlock` 里的机构名、页面标题与行数都取自某一份具体
数据,而回归测试需要的只是形状:一张有很多行的 markdown 表格 + 表头 + 分隔行。
取值换成中性的示例数据 —— 机构名 `示例科技有限公司`、行标识 `成员 N`、标题
`证书台账`、行数 90(切 1..61 + 62..90),断言里的 92 = 90 行 + 表头 + 分隔行。

断言逻辑一行未动,5 个续写/上限/哨兵用例全 PASS。
2026-09-28 20:19:52 +08:00
lyingbug 9114e4e4f9
fix(citations): 修复原文定位、高亮范围与 DocReader 启动失败 (#3794)
* fix(citations): verify source locations and recover document previews

* chore: exclude local research notes from pull request
2026-09-27 20:32:26 +08:00
wizardchen 6c83d7ab47 revert: take the plugin system back out of main
Reverts the eleven plugin system PRs merged on 2026-09-26 so they can be
reviewed before landing:

* a829d7cc9 agent tools served by plugins (#3733)
* 4f5d475c3 Jira example plugin (#3730)
* 01222aac8 dynamic form options, OAuth connections and resource limits (#3729)
* cf502ba46 event delivery and webhooks (#3728)
* 996696057 sandboxed plugin pages (#3727)
* da4ef68d9 standalone plugin hosts (#3725)
* 728007ada remote runtime, Python SDK (#3724)
* ff49f9491 Host API and document parsers (#3721)
* 4328ab26a code plugins (#3720)
* ed63e35cc declarative plugins (#3716)
* c91a8d11f plugin system foundation (#3711)

The tree is back to 47773b5bd, migrations included: no environment ran
the plugin migrations (versioned 000115-000119, sqlite 000034-000038).
2026-09-26 14:58:18 +08:00
lyingbug 01222aac8e
feat(plugin): dynamic form options, OAuth connections and resource limits (P2 batch 7) (#3729)
* feat(plugin): dynamic form options, OAuth connections and resource limits
* fix(plugin): show what an options list waits for as a hint, not an error
2026-09-26 14:47:37 +08:00
lyingbug cf502ba46a
feat(plugin): event delivery and webhooks for plugins (P2 batch 6) (#3728)
* feat(plugin): event delivery and webhooks for plugins
2026-09-26 14:47:13 +08:00