fix: reject cross-store reuse_vectors knowledge move
Moving knowledge with mode=reuse_vectors copies vector index entries
directly between knowledge bases, which only works when both KBs are
bound to the same vector store (CopyIndices is routed through the source
store). Nothing rejected a cross-store reuse_vectors move, so it would
copy target-KB rows into the source store and then delete the source
indices — corrupting vector data. The move endpoint validated only the
embedding model, and ListMoveTargets surfaces same-model KBs regardless
of their store binding, so a cross-store target is reachable.
Reject reuse_vectors moves whose source and target KBs are bound to
different vector stores:
- MoveKnowledge handler: synchronous 400 before enqueueing, with a
message pointing the caller at reparse mode.
- moveOneKnowledge: re-check before marking the knowledge as processing,
so a rejected move leaves it untouched rather than stranded.
- moveKnowledgeReuseVectors: a top-of-function guard as defense in depth
for any directly enqueued task, satisfying the pre-existing contract
noted in the comment ("callers must reject cross-store moves").
reparse mode is unaffected: it re-indexes into the target store from
scratch and is the supported way to move across stores.
This commit is contained in:
@@ -2015,6 +2015,18 @@ func (h *KnowledgeHandler) MoveKnowledge(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// reuse_vectors copies index entries directly between KBs, which only works
|
||||
// inside the same VectorStore backend. A cross-store reuse_vectors move would
|
||||
// route CopyIndices through the SOURCE store and then delete the source
|
||||
// indices, corrupting the vector data. Reject it and point the caller at
|
||||
// reparse mode, which re-indexes into the target store safely.
|
||||
if req.Mode == "reuse_vectors" && !sourceKB.SharesStoreWith(targetKB) {
|
||||
c.Error(errors.NewBadRequestError(
|
||||
"reuse_vectors move across different vector stores is not supported; " +
|
||||
"use reparse mode to move into a different store"))
|
||||
return
|
||||
}
|
||||
|
||||
// Validate all knowledge IDs belong to source KB and are in completed status
|
||||
for _, kID := range req.KnowledgeIDs {
|
||||
knowledge, err := h.kgService.GetKnowledgeByID(ctx, kID)
|
||||
|
||||
Reference in New Issue
Block a user