From bf2f87d59c09e7c4e44be634f5f68d456060b131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Gill=C3=A9?= Date: Sat, 10 Feb 2024 14:33:52 +0100 Subject: [PATCH] Rename embedding constructors It's good practice to name constructors "New..." --- db.go | 2 +- embedding.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/db.go b/db.go index 7689493..24cc149 100644 --- a/db.go +++ b/db.go @@ -35,7 +35,7 @@ func NewDB() *DB { // Uses the default embedding function if not provided. func (c *DB) CreateCollection(name string, metadata map[string]string, embeddingFunc EmbeddingFunc) *Collection { if embeddingFunc == nil { - embeddingFunc = CreateEmbeddingsDefault() + embeddingFunc = NewEmbeddingFuncDefault() } collection := newCollection(name, metadata, embeddingFunc) diff --git a/embedding.go b/embedding.go index 7dbc388..160e2f2 100644 --- a/embedding.go +++ b/embedding.go @@ -29,28 +29,28 @@ type openAIResponse struct { } `json:"data"` } -// CreateEmbeddingsDefault returns a function that creates embeddings for a document +// NewEmbeddingFuncDefault returns a function that creates embeddings for a document // using OpenAI`s "text-embedding-3-small" model via their API. // The model supports a maximum document length of 8191 tokens. // The API key is read from the environment variable "OPENAI_API_KEY". -func CreateEmbeddingsDefault() EmbeddingFunc { +func NewEmbeddingFuncDefault() EmbeddingFunc { apiKey := os.Getenv("OPENAI_API_KEY") - return CreateEmbeddingsOpenAI(apiKey, EmbeddingModelOpenAI3Small) + return NewEmbeddingFuncOpenAI(apiKey, EmbeddingModelOpenAI3Small) } -// CreateEmbeddingsOpenAI returns a function that creates embeddings for a document +// NewEmbeddingFuncOpenAI returns a function that creates embeddings for a document // using the OpenAI API. -func CreateEmbeddingsOpenAI(apiKey string, model EmbeddingModelOpenAI) EmbeddingFunc { - return CreateEmbeddingsOpenAICompat(BaseURLOpenAI, apiKey, string(model)) +func NewEmbeddingFuncOpenAI(apiKey string, model EmbeddingModelOpenAI) EmbeddingFunc { + return NewEmbeddingFuncOpenAICompat(BaseURLOpenAI, apiKey, string(model)) } -// CreateEmbeddingsOpenAICompat returns a function that creates embeddings for a document +// NewEmbeddingFuncOpenAICompat returns a function that creates embeddings for a document // using an OpenAI compatible API. For example: // - Azure OpenAI: https://azure.microsoft.com/en-us/products/ai-services/openai-service // - LitLLM: https://github.com/BerriAI/litellm // - Ollama: https://github.com/ollama/ollama/blob/main/docs/openai.md // - etc. -func CreateEmbeddingsOpenAICompat(baseURL, apiKey, model string) EmbeddingFunc { +func NewEmbeddingFuncOpenAICompat(baseURL, apiKey, model string) EmbeddingFunc { // We don't set a default timeout here, although it's usually a good idea. // In our case though, the library user can set the timeout on the context, // and it might have to be a long timeout, depending on the document size.