Skip to content
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

Stop exporting Collection.Metadata #16

Merged
merged 1 commit into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// that don't have embeddings yet.
type Collection struct {
Name string
Metadata map[string]string
metadata map[string]string

documents map[string]*document
documentsLock sync.RWMutex
Expand All @@ -25,7 +25,7 @@ type Collection struct {
func newCollection(name string, metadata map[string]string, embed EmbeddingFunc) *Collection {
return &Collection{
Name: name,
Metadata: metadata,
metadata: metadata,

documents: make(map[string]*document),

Expand Down
6 changes: 3 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (c *DB) GetCollection(name string) *Collection {
return nil
}

newMetadata := make(map[string]string, len(orig.Metadata))
for k, v := range orig.Metadata {
newMetadata := make(map[string]string, len(orig.metadata))
for k, v := range orig.metadata {
newMetadata[k] = v
}

Expand All @@ -94,7 +94,7 @@ func (c *DB) GetCollection(name string) *Collection {

return &Collection{
Name: orig.Name,
Metadata: newMetadata,
metadata: newMetadata,

documents: make(map[string]*document, len(orig.documents)),

Expand Down
32 changes: 18 additions & 14 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ func TestDB_ListCollections(t *testing.T) {
if c.Name != name {
t.Error("expected name", name, "got", c.Name)
}
if len(c.Metadata) != 1 {
t.Error("expected 1 metadata, got", len(c.Metadata))
}
if c.Metadata["foo"] != "bar" {
t.Error("expected metadata", metadata, "got", c.Metadata)
}

// And it should be a copy
// TODO: Check metadata when it's accessible (e.g. with GetMetadata())
// if len(c.Metadata) != 1 {
// t.Error("expected 1 metadata, got", len(c.Metadata))
// }
// if c.Metadata["foo"] != "bar" {
// t.Error("expected metadata", metadata, "got", c.Metadata)
// }
// TODO: Same for documents and EmbeddingFunc

// And it should be a copy. Adding a value here should not reflect on the DB's
// collection.
res["foo"] = &chromem.Collection{}
if len(db.ListCollections()) != 1 {
t.Error("expected 1 collection, got", len(db.ListCollections()))
Expand All @@ -68,12 +71,13 @@ func TestDB_GetCollection(t *testing.T) {
if c.Name != name {
t.Error("expected name", name, "got", c.Name)
}
if len(c.Metadata) != 1 {
t.Error("expected 1 metadata, got", len(c.Metadata))
}
if c.Metadata["foo"] != "bar" {
t.Error("expected metadata", metadata, "got", c.Metadata)
}
// TODO: Check metadata when it's accessible (e.g. with GetMetadata())
// if len(c.Metadata) != 1 {
// t.Error("expected 1 metadata, got", len(c.Metadata))
// }
// if c.Metadata["foo"] != "bar" {
// t.Error("expected metadata", metadata, "got", c.Metadata)
// }
// TODO: Check documents content as soon as we have access to them
// TODO: Same for the EmbeddingFunc
// TODO: Check documents map being a copy as soon as we have access to it
Expand Down
Loading