Skip to content

Commit

Permalink
Improve locking around collection's documents
Browse files Browse the repository at this point in the history
  • Loading branch information
philippgille committed Dec 30, 2023
1 parent 9d8ce4a commit cefec66
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ func (c *Collection) Add(ctx context.Context, ids []string, embeddings [][]float
var embedding []float32
var metadata map[string]string
var err error
c.documentsLock.Lock()
defer c.documentsLock.Unlock()
for i, document := range documents {
if len(embeddings) != 0 {
embedding = embeddings[i]
}
if len(metadatas) != 0 {
metadata = metadatas[i]
}
c.documentsLock.Lock()
// We don't defer the unlock because we want to unlock much earlier
c.documents[ids[i]], err = newDocument(ctx, ids[i], embedding, metadata, document, c.embed)
c.documentsLock.Unlock()
if err != nil {
return err
}
Expand Down

0 comments on commit cefec66

Please sign in to comment.