feat: 批量更新tag时更新索引字段

This commit is contained in:
wizardchen
2025-12-30 17:43:29 +08:00
committed by lyingbug
parent 8832d70e19
commit da1dcb0cda
8 changed files with 288 additions and 9 deletions
@@ -427,6 +427,58 @@ func (q *qdrantRepository) BatchUpdateChunkEnabledStatus(ctx context.Context, ch
return nil
}
// BatchUpdateChunkTagID updates the tag ID of chunks in batch
func (q *qdrantRepository) BatchUpdateChunkTagID(ctx context.Context, chunkTagMap map[string]string) error {
log := logger.GetLogger(ctx)
if len(chunkTagMap) == 0 {
log.Warn("[Qdrant] Empty chunk tag map provided, skipping")
return nil
}
log.Infof("[Qdrant] Batch updating chunk tag ID, count: %d", len(chunkTagMap))
// Get all collections that match our base name pattern
collections, err := q.client.ListCollections(ctx)
if err != nil {
log.Errorf("[Qdrant] Failed to list collections: %v", err)
return fmt.Errorf("failed to list collections: %w", err)
}
// Group chunks by tag ID for batch updates
tagGroups := make(map[string][]string)
for chunkID, tagID := range chunkTagMap {
tagGroups[tagID] = append(tagGroups[tagID], chunkID)
}
// Update in all matching collections
for _, collectionName := range collections {
// Only process collections that start with our base name
if len(collectionName) <= len(q.collectionBaseName) ||
collectionName[:len(q.collectionBaseName)] != q.collectionBaseName {
continue
}
// Update chunks for each tag ID
for tagID, chunkIDs := range tagGroups {
_, err := q.client.SetPayload(ctx, &qdrant.SetPayloadPoints{
CollectionName: collectionName,
Payload: qdrant.NewValueMap(map[string]any{fieldTagID: tagID}),
PointsSelector: qdrant.NewPointsSelectorFilter(&qdrant.Filter{
Must: []*qdrant.Condition{
qdrant.NewMatchKeywords(fieldChunkID, chunkIDs...),
},
}),
})
if err != nil {
log.Warnf("[Qdrant] Failed to update chunks with tag_id %s in %s: %v", tagID, collectionName, err)
}
}
}
log.Infof("[Qdrant] Batch update chunk tag ID completed")
return nil
}
func (q *qdrantRepository) getBaseFilter(params types.RetrieveParams) *qdrant.Filter {
must := make([]*qdrant.Condition, 0)
mustNot := make([]*qdrant.Condition, 0)