@@ -3,7 +3,6 @@ package grpc
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
- "fmt"
7
6
8
7
"github.com/chroma-core/chroma/go/pkg/grpcutils"
9
8
@@ -250,31 +249,15 @@ func (s *Server) GetCollectionWithSegments(ctx context.Context, req *coordinator
250
249
}
251
250
return res , grpcutils .BuildInternalGrpcError (err .Error ())
252
251
}
253
-
254
252
res .Collection = convertCollectionToProto (collection )
253
+
255
254
segmentpbList := make ([]* coordinatorpb.Segment , 0 , len (segments ))
256
- scopeToSegmentMap := map [coordinatorpb.SegmentScope ]* coordinatorpb.Segment {}
257
255
for _ , segment := range segments {
258
256
segmentpb := convertSegmentToProto (segment )
259
- scopeToSegmentMap [segmentpb .GetScope ()] = segmentpb
260
257
segmentpbList = append (segmentpbList , segmentpb )
261
258
}
262
-
263
- if len (segmentpbList ) != 3 {
264
- log .Error ("GetCollectionWithSegments failed. Unexpected number of collection segments" , zap .String ("collection_id" , collectionID ))
265
- return res , grpcutils .BuildInternalGrpcError (fmt .Sprintf ("Unexpected number of segments for collection %s: %d" , collectionID , len (segmentpbList )))
266
- }
267
-
268
- scopes := []coordinatorpb.SegmentScope {coordinatorpb .SegmentScope_METADATA , coordinatorpb .SegmentScope_RECORD , coordinatorpb .SegmentScope_VECTOR }
269
-
270
- for _ , scope := range scopes {
271
- if _ , exists := scopeToSegmentMap [scope ]; ! exists {
272
- log .Error ("GetCollectionWithSegments failed. Collection segment scope not found" , zap .String ("collection_id" , collectionID ), zap .String ("missing_scope" , scope .String ()))
273
- return res , grpcutils .BuildInternalGrpcError (fmt .Sprintf ("Missing segment scope for collection %s: %s" , collectionID , scope .String ()))
274
- }
275
- }
276
-
277
259
res .Segments = segmentpbList
260
+
278
261
return res , nil
279
262
}
280
263
@@ -360,6 +343,53 @@ func (s *Server) UpdateCollection(ctx context.Context, req *coordinatorpb.Update
360
343
return res , nil
361
344
}
362
345
346
+ func (s * Server ) ForkCollection (ctx context.Context , req * coordinatorpb.ForkCollectionRequest ) (* coordinatorpb.ForkCollectionResponse , error ) {
347
+ res := & coordinatorpb.ForkCollectionResponse {}
348
+
349
+ sourceCollectionID := req .SourceCollectionId
350
+ parsedSourceCollectionID , err := types .ToUniqueID (& sourceCollectionID )
351
+ if err != nil {
352
+ log .Error ("ForkCollection failed. Failed to parse source collection id" , zap .Error (err ), zap .String ("collection_id" , sourceCollectionID ))
353
+ return res , grpcutils .BuildInternalGrpcError (err .Error ())
354
+ }
355
+
356
+ targetCollectionID := req .TargetCollectionId
357
+ parsedTargetCollectionID , err := types .ToUniqueID (& targetCollectionID )
358
+ if err != nil {
359
+ log .Error ("ForkCollection failed. Failed to parse target collection id" , zap .Error (err ), zap .String ("collection_id" , targetCollectionID ))
360
+ return res , grpcutils .BuildInternalGrpcError (err .Error ())
361
+ }
362
+
363
+ forkCollection := & model.ForkCollection {
364
+ SourceCollectionID : parsedSourceCollectionID ,
365
+ SourceCollectionLogCompactionOffset : req .SourceCollectionLogCompactionOffset ,
366
+ SourceCollectionLogEnumerationOffset : req .SourceCollectionLogEnumerationOffset ,
367
+ TargetCollectionID : parsedTargetCollectionID ,
368
+ TargetCollectionName : req .TargetCollectionName ,
369
+ }
370
+ collection , segments , err := s .coordinator .ForkCollection (ctx , forkCollection )
371
+ if err != nil {
372
+ log .Error ("ForkCollection failed. " , zap .Error (err ), zap .String ("collection_id" , sourceCollectionID ))
373
+ if err == common .ErrCollectionNotFound {
374
+ return res , grpcutils .BuildNotFoundGrpcError (err .Error ())
375
+ }
376
+ if err == common .ErrCollectionUniqueConstraintViolation {
377
+ return res , grpcutils .BuildAlreadyExistsGrpcError (err .Error ())
378
+ }
379
+ return res , grpcutils .BuildInternalGrpcError (err .Error ())
380
+ }
381
+ res .Collection = convertCollectionToProto (collection )
382
+
383
+ segmentpbList := make ([]* coordinatorpb.Segment , 0 , len (segments ))
384
+ for _ , segment := range segments {
385
+ segmentpb := convertSegmentToProto (segment )
386
+ segmentpbList = append (segmentpbList , segmentpb )
387
+ }
388
+ res .Segments = segmentpbList
389
+
390
+ return res , nil
391
+ }
392
+
363
393
func (s * Server ) ListCollectionVersions (ctx context.Context , req * coordinatorpb.ListCollectionVersionsRequest ) (* coordinatorpb.ListCollectionVersionsResponse , error ) {
364
394
collectionID , err := types .ToUniqueID (& req .CollectionId )
365
395
if err != nil {
0 commit comments