(embClient *embedder.EmbeddingClient, tree *object.Tree, redisClient *redis.Client, redisearchClient *redisearch.Client, url string)
| 335 | } |
| 336 | |
| 337 | func processRedisEmbeddings(embClient *embedder.EmbeddingClient, tree *object.Tree, redisClient *redis.Client, redisearchClient *redisearch.Client, url string) { |
| 338 | // Check for existing processed hashes |
| 339 | existingHashes := make(map[string]bool) |
| 340 | existingTreeHash, err := redisClient.Get(context.Background(), fmt.Sprintf("%s:embedding:tree", url)).Result() |
| 341 | if err != nil && err != redis.Nil { |
| 342 | log.Fatal(err) |
| 343 | } |
| 344 | if err == nil { |
| 345 | existingHashesStr, err := redisClient.Get(context.Background(), fmt.Sprintf("%s:embedding:tree:%s", url, existingTreeHash)).Result() |
| 346 | if err != nil && err != redis.Nil { |
| 347 | log.Fatal(err) |
| 348 | } |
| 349 | for _, h := range strings.Split(existingHashesStr, ",") { |
| 350 | existingHashes[h] = true |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | hashes := make(map[string]bool) |
| 355 | filesBatch := []embedder.CodeEmbeddingRequest{} |
| 356 | treeIter := tree.Files() |
| 357 | batchSize := 10 |
| 358 | count := 0 |
| 359 | |
| 360 | for { |
| 361 | fmt.Printf("Processing file\n") |
| 362 | file, err := treeIter.Next() |
| 363 | if err != nil { |
| 364 | if err == io.EOF { |
| 365 | break // No more files |
| 366 | } |
| 367 | log.Fatal(err) |
| 368 | } |
| 369 | |
| 370 | // Skip unsupported file types |
| 371 | ext := filepath.Ext(file.Name) |
| 372 | if _, ok := supportedLanguages[ext]; !ok { |
| 373 | fmt.Printf("Skipping file '%s' since it is not supported\n", file.Name) |
| 374 | continue |
| 375 | } |
| 376 | |
| 377 | hashes[file.Hash.String()] = true |
| 378 | |
| 379 | // Process only if the file hash is not in the existing hashes |
| 380 | if !existingHashes[file.Hash.String()] { |
| 381 | content, err := file.Contents() |
| 382 | if err != nil { |
| 383 | log.Fatal(err) |
| 384 | } |
| 385 | |
| 386 | filesBatch = append(filesBatch, embedder.CodeEmbeddingRequest{ |
| 387 | Path: file.Name, |
| 388 | Content: content, |
| 389 | Hash: file.Hash.String(), |
| 390 | }) |
| 391 | count++ |
| 392 | |
| 393 | // Process in batches of 10 |
| 394 | if count >= batchSize { |
no test coverage detected