-
Notifications
You must be signed in to change notification settings - Fork 54
2 additional methods to help with managing of collections: GetAllDocuments & GetDocumentsByMetadata #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2 additional methods to help with managing of collections: GetAllDocuments & GetDocumentsByMetadata #118
Changes from 4 commits
262e33f
11878bc
286293e
42cf7dd
b52b5d5
80e4c87
c7299f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -558,6 +558,50 @@ func (c *Collection) queryEmbedding(ctx context.Context, queryEmbedding, negativ | |
| return res, nil | ||
| } | ||
|
|
||
| func (c *Collection) GetAllDocuments(_ context.Context, fetchDeep bool) ([]Document, error) { | ||
philippgille marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| c.documentsLock.RLock() | ||
| defer c.documentsLock.RUnlock() | ||
|
|
||
| results := make([]Document, 0, len(c.documents)) | ||
| for _, doc := range c.documents { | ||
| // Clone the document to avoid concurrent modification by reading goroutine | ||
| docCopy := *doc | ||
| if fetchDeep { | ||
| docCopy.Metadata = maps.Clone(doc.Metadata) | ||
| docCopy.Embedding = slices.Clone(doc.Embedding) | ||
| } else { | ||
| docCopy.Metadata = nil | ||
| docCopy.Embedding = nil | ||
| } | ||
| results = append(results, docCopy) | ||
| } | ||
| return results, nil | ||
| } | ||
|
|
||
| func (c *Collection) GetDocumentsByMetadata(_ context.Context, where map[string]string) ([]Document, error) { | ||
| c.documentsLock.RLock() | ||
| defer c.documentsLock.RUnlock() | ||
|
|
||
| var results []Document | ||
| for _, doc := range c.documents { | ||
| match := true | ||
| for key, value := range where { | ||
| if docVal, ok := doc.Metadata[key]; !ok || docVal != value { | ||
| match = false | ||
| break | ||
| } | ||
| } | ||
| if match { | ||
| // Clone the document to avoid concurrent modification by reading goroutine | ||
| docCopy := *doc | ||
| docCopy.Metadata = maps.Clone(doc.Metadata) | ||
| docCopy.Embedding = slices.Clone(doc.Embedding) | ||
| results = append(results, docCopy) | ||
| } | ||
| } | ||
| return results, nil | ||
| } | ||
|
|
||
| // getDocPath generates the path to the document file. | ||
| func (c *Collection) getDocPath(docID string) string { | ||
| safeID := hash2hex(docID) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.