Skip to content

Commit

Permalink
Merge pull request #3 from philippgille/rename-client-to-db
Browse files Browse the repository at this point in the history
Rename Client to DB
  • Loading branch information
philippgille authored Feb 4, 2024
2 parents 91acf87 + 9b04b8d commit 05302a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ import "github.com/philippgille/chromem-go"

func main() {
// Set up chromem-go in-memory, for easy prototyping. Persistence will be added in the future.
client := chromem.NewClient()
// We call it DB instead of client because there's no client-server separation. The DB is embedded.
db := chromem.NewDB()

// Create collection. GetCollection, GetOrCreateCollection, DeleteCollection will be added in the future.
collection := client.CreateCollection("all-my-documents", nil, nil)
collection := db.CreateCollection("all-my-documents", nil, nil)

// Add docs to the collection. Update and delete will be added in the future.
// Row-based API will be added when Chroma adds it!
Expand Down
18 changes: 9 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
// own function, using any model you like.
type EmbeddingFunc func(ctx context.Context, document string) ([]float32, error)

// Client is the chromem-go client. It holds collections, which hold documents.
// DB is the chromem-go database. It holds collections, which hold documents.
//
// +--------+ 1-n +------------+ n-n +----------+
// | Client |-----------| Collection |-----------| Document |
// +--------+ +------------+ +----------+
type Client struct {
// +----+ 1-n +------------+ n-n +----------+
// | DB |-----------| Collection |-----------| Document |
// +----+ +------------+ +----------+
type DB struct {
collections map[string]*Collection
collectionsLock sync.RWMutex
}

// NewClient creates a new chromem-go client.
func NewClient() *Client {
return &Client{
// NewDB creates a new chromem-go DB.
func NewDB() *DB {
return &DB{
collections: make(map[string]*Collection),
}
}
Expand All @@ -33,7 +33,7 @@ func NewClient() *Client {
// - metadata: Optional metadata to associate with the collection.
// - embeddingFunc: Optional function to use to embed documents.
// Uses the default embedding function if not provided.
func (c *Client) CreateCollection(name string, metadata map[string]string, embeddingFunc EmbeddingFunc) *Collection {
func (c *DB) CreateCollection(name string, metadata map[string]string, embeddingFunc EmbeddingFunc) *Collection {
if embeddingFunc == nil {
embeddingFunc = CreateEmbeddingsDefault()
}
Expand Down
4 changes: 2 additions & 2 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func main() {
// Now we use our vector database for retrieval augmented generation (RAG) to provide the LLM with context.

// Set up chromem-go in-memory, for easy prototyping.
client := chromem.NewClient()
db := chromem.NewDB()
// Create collection.
collection := client.CreateCollection("philippgille-projects", nil, nil)
collection := db.CreateCollection("philippgille-projects", nil, nil)
// Add docs to the collection.
// Here we're adding the READMEs of some of my projects.
projects := []string{"gokv", "ln-paywall", "chromem-go"}
Expand Down

0 comments on commit 05302a3

Please sign in to comment.