MCPcopy Index your code
hub / github.com/53AI/53AIHub / insertWithAutoCreate

Method insertWithAutoCreate

api/service/rag/entity_vector.go:266–289  ·  view source on GitHub ↗
(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int)

Source from the content-addressed store, hash-verified

264}
265
266func (s *EntityVectorService) insertWithAutoCreate(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int) error {
267 err := s.vectorDB.Insert(ctx, collection, []vectorstore.VectorRecord{record})
268 if err == nil {
269 return nil
270 }
271 if vsErr, ok := err.(*vectorstore.VectorStoreError); ok {
272 if vsErr.Code == vectorstore.ErrCodeCollectionNotFound || vsErr.Code == vectorstore.ErrCodeUnknown {
273 collectionConfig := vectorstore.CollectionConfig{
274 Name: collection,
275 Dimension: dimension,
276 Metric: "cosine",
277 IndexType: "HNSW",
278 }
279 if createErr := s.vectorDB.CreateCollection(ctx, collectionConfig); createErr != nil && !vectorstore.IsExistsError(createErr) {
280 return createErr
281 }
282 if insertErr := s.vectorDB.Insert(ctx, collection, []vectorstore.VectorRecord{record}); insertErr != nil {
283 return insertErr
284 }
285 return nil
286 }
287 }
288 return err
289}
290
291func (s *EntityVectorService) updateWithAutoCreate(ctx context.Context, collection string, record vectorstore.VectorRecord, dimension int) error {
292 err := s.vectorDB.Update(ctx, collection, []vectorstore.VectorRecord{record})

Callers

nothing calls this directly

Calls 2

InsertMethod · 0.65
CreateCollectionMethod · 0.65

Tested by

no test coverage detected