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

Change OpenAPI embedding model to new generation #4

Merged
merged 1 commit into from
Feb 4, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Initially, only a minimal subset of all of Chroma's interface is implemented or
- [X] Zero dependencies on third party libraries
- [X] Concurrent processing (when adding and querying documents)
- Embedding creators:
- [X] [OpenAI ada v2](https://platform.openai.com/docs/guides/embeddings/embedding-models) (default)
- [X] [OpenAI text-embedding-3-small](https://platform.openai.com/docs/guides/embeddings/embedding-models) (default)
- [X] Bring your own
- [ ] [Mistral (API)](https://docs.mistral.ai/api/#operation/createEmbedding)
- [ ] [ollama](https://ollama.ai/)
Expand Down
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

// EmbeddingFunc is a function that creates embeddings for a given document.
// chromem-go will use OpenAI`s ada v2 model by default, but you can provide your
// own function, using any model you like.
// chromem-go will use OpenAI`s "text-embedding-3-small" model by default,
// but you can provide your own function, using any model you like.
type EmbeddingFunc func(ctx context.Context, document string) ([]float32, error)

// DB is the chromem-go database. It holds collections, which hold documents.
Expand Down
18 changes: 9 additions & 9 deletions embedding.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

const (
baseURLOpenAI = "https://api.openai.com/v1"
embeddingModelOpenAI = "text-embedding-ada-002"
baseURLOpenAI = "https://api.openai.com/v1"
embeddingModelOpenAI3Small = "text-embedding-3-small"
)

type openAIResponse struct {
Expand All @@ -22,18 +22,18 @@ type openAIResponse struct {
} `json:"data"`
}

// CreateEmbeddingsDefault returns a function that creates embeddings for a document using using
// OpenAI`s ada v2 model via their API.
// The model supports a maximum document length of 8192 tokens.
// CreateEmbeddingsDefault 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 {
apiKey := os.Getenv("OPENAI_API_KEY")
return CreateEmbeddingsOpenAI(apiKey)
}

// CreateEmbeddingsOpenAI returns a function that creates the embeddings for a document
// using OpenAI`s ada v2 model via their API.
// The model supports a maximum document length of 8192 tokens.
// CreateEmbeddingsDefault 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.
func CreateEmbeddingsOpenAI(apiKey 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,
Expand All @@ -44,7 +44,7 @@ func CreateEmbeddingsOpenAI(apiKey string) EmbeddingFunc {
// Prepare the request body.
reqBody, err := json.Marshal(map[string]string{
"input": document,
"model": embeddingModelOpenAI,
"model": embeddingModelOpenAI3Small,
})
if err != nil {
return nil, fmt.Errorf("couldn't marshal request body: %w", err)
Expand Down
Loading