MCPcopy Create free account
hub / github.com/encoder-run/operator / processAndSaveEmbeddings

Function processAndSaveEmbeddings

cmd/repositoryembedder/main.go:306–335  ·  view source on GitHub ↗
(embClient *embedder.EmbeddingClient, db *gorm.DB, filesBatch *[]embedder.CodeEmbeddingRequest, url string)

Source from the content-addressed store, hash-verified

304}
305
306func processAndSaveEmbeddings(embClient *embedder.EmbeddingClient, db *gorm.DB, filesBatch *[]embedder.CodeEmbeddingRequest, url string) {
307 embeddings, err := embClient.FetchEmbeddings(*filesBatch)
308 if err != nil {
309 log.Fatal(err)
310 }
311 for filePath, embs := range embeddings.Results {
312 for _, emb := range embs.Embeddings {
313 newEmb := database.CodeEmbedding{
314 URL: url,
315 FileHash: emb.FileHash,
316 FilePath: filePath,
317 ChunkID: emb.ChunkID,
318 StartIndex: emb.StartIndex,
319 EndIndex: emb.EndIndex,
320 Embedding: pgvector.NewVector(emb.Embedding), // Assuming emb.Vector is the appropriate data structure
321 }
322 // Upsert operation using Clauses with ON CONFLICT
323 if err := db.Clauses(clause.OnConflict{
324 Columns: []clause.Column{{Name: "chunk_id"}, {Name: "file_hash"}, {Name: "url"}, {Name: "file_path"}}, // Columns part of the unique constraint
325 DoUpdates: clause.Assignments(map[string]interface{}{ // Update these fields if there is a conflict
326 "start_index": newEmb.StartIndex,
327 "end_index": newEmb.EndIndex,
328 "embedding": newEmb.Embedding,
329 }),
330 }).Create(&newEmb).Error; err != nil {
331 log.Fatalf("failed to save or update embedding: %v", err)
332 }
333 }
334 }
335}
336
337func processRedisEmbeddings(embClient *embedder.EmbeddingClient, tree *object.Tree, redisClient *redis.Client, redisearchClient *redisearch.Client, url string) {
338 // Check for existing processed hashes

Callers 1

Calls 1

FetchEmbeddingsMethod · 0.80

Tested by

no test coverage detected