refactor: Improve Elasticsearch query construction and error handling

This commit is contained in:
wizardchen
2025-11-25 22:06:43 +08:00
parent 64c44c9e27
commit 2f45bf7d86
12 changed files with 158 additions and 154 deletions
+7
View File
@@ -145,6 +145,9 @@ func (b *graphBuilder) extractEntities(ctx context.Context, chunk *types.Chunk)
defer b.mutex.Unlock()
for _, entity := range extractedEntities {
if entity == nil {
continue
}
if entity.Title == "" || entity.Description == "" {
log.WithField("entity", entity).Warn("Invalid entity with empty title or description")
continue
@@ -272,6 +275,10 @@ func (b *graphBuilder) extractRelationships(ctx context.Context,
relationship.Source, relationship.Target, relationship.ID)
} else {
// This relationship already exists, update its properties
if existingRel == nil {
log.Warnf("existingRel is nil, skip update")
continue
}
chunkIDsAdded := 0
for _, chunkID := range relationChunkIDs {
if !slices.Contains(existingRel.ChunkIDs, chunkID) {