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

feat: Add openai embedding #36366

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

junjiejiangjjj
Copy link

@junjiejiangjjj junjiejiangjjj commented Sep 19, 2024

@sre-ci-robot sre-ci-robot added the do-not-merge/work-in-progress Don't merge even CI passed. label Sep 19, 2024
@sre-ci-robot
Copy link
Contributor

Welcome @junjiejiangjjj! It looks like this is your first PR to milvus-io/milvus 🎉

@sre-ci-robot sre-ci-robot added the size/L Denotes a PR that changes 100-499 lines. label Sep 19, 2024
@mergify mergify bot added dco-passed DCO check passed. kind/feature Issues related to feature request from users labels Sep 19, 2024
Copy link
Contributor

mergify bot commented Sep 19, 2024

@junjiejiangjjj Please associate the related issue to the body of your Pull Request. (eg. “issue: #”)

@junjiejiangjjj junjiejiangjjj force-pushed the embedding branch 3 times, most recently from fd701cd to 5407f22 Compare September 20, 2024 03:03
@sre-ci-robot sre-ci-robot added size/XL Denotes a PR that changes 500-999 lines. and removed size/L Denotes a PR that changes 100-499 lines. labels Sep 23, 2024
@junjiejiangjjj junjiejiangjjj force-pushed the embedding branch 6 times, most recently from 200bc3b to ed7d332 Compare September 26, 2024 07:25
@sre-ci-robot sre-ci-robot added size/XXL Denotes a PR that changes 1000+ lines. and removed size/XL Denotes a PR that changes 500-999 lines. labels Sep 26, 2024
@junjiejiangjjj junjiejiangjjj force-pushed the embedding branch 2 times, most recently from 38243dd to 0d0286e Compare October 8, 2024 08:26
@sre-ci-robot sre-ci-robot added the area/dependency Pull requests that update a dependency file label Oct 8, 2024
@junjiejiangjjj junjiejiangjjj force-pushed the embedding branch 3 times, most recently from 0f30960 to 7950316 Compare October 11, 2024 03:53
@junjiejiangjjj
Copy link
Author

rerun go-sdk

Copy link
Contributor

mergify bot commented Dec 17, 2024

@junjiejiangjjj E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 17, 2024

@junjiejiangjjj go-sdk check failed, comment rerun go-sdk can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 18, 2024

@junjiejiangjjj go-sdk check failed, comment rerun go-sdk can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 18, 2024

@junjiejiangjjj E2e jenkins job failed, comment /run-cpu-e2e can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 19, 2024

@junjiejiangjjj cpp-unit-test check failed, comment rerun cpp-unit-test can trigger the job again.

Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjiejiangjjj <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Signed-off-by: junjie.jiang <[email protected]>
Copy link
Contributor

mergify bot commented Dec 26, 2024

@junjiejiangjjj go-sdk check failed, comment rerun go-sdk can trigger the job again.

Copy link
Contributor

mergify bot commented Dec 26, 2024

@junjiejiangjjj cpp-unit-test check failed, comment rerun cpp-unit-test can trigger the job again.

Copy link
Collaborator

@zhengbuqian zhengbuqian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see several comments from last review nor addressed neither replied, please take a look. Thanks!

apiKey: apiKey,
url: url,
},
apiVersion: "2024-06-01",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to pass in this apiVersion instead of hard coding?

based on https://learn.microsoft.com/en-us/azure/ai-services/openai/api-version-deprecation seems there is little breaking change introduced to the API, mostly new features.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New features brought by the new version generally require code adaptation, so it is not very meaningful to open the configuration of apiVersion.

@@ -416,14 +417,24 @@ func (t *searchTask) initAdvancedSearchRequest(ctx context.Context) error {
zap.Stringer("plan", plan)) // may be very large if large term passed.
}

var err error
if function.HasFunctions(t.schema.CollectionSchema.Functions, []int64{}) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping


// TODO: unify the function implementation, storage/utils.go & proxy/util.go
func IsBM25FunctionOutputField(field *schemapb.FieldSchema) bool {
return field.GetIsFunctionOutput() && field.GetDataType() == schemapb.DataType_SparseFloatVector
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not true? other models can also have sparse float vector output

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no problem right now. After the implementation of bm25 and the model function is unified, the relevant code will not be needed.

return nil, err
}

if resp.StatusCode != 200 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {

OutputType string `json:"output_type,omitempty"`
}

type EmbeddingRequest struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmbeddingRequest can be private? by lowercase the first letter embeddingRequest. I did a quick search and find no usage of this class outside this file. correct me IIW. This comment applies to many other structs in this and other files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only used in test files under milvus/internal/util/function/

}

if inputs[0].Type != schemapb.DataType_VarChar {
return nil, fmt.Errorf("Text embedding only supports varchar field, the input is not varchar")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text embedding only supports varchar field as input field, but got %s


func (runner *TextEmebddingFunction) ProcessBulkInsert(inputs []storage.FieldData) (map[storage.FieldID]storage.FieldData, error) {
if len(inputs) != 1 {
return nil, fmt.Errorf("OpenAIEmbedding function only receives one input, bug got [%d]", len(inputs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines +92 to +99
dim, err = strconv.ParseInt(param.Value, 10, 64)
if err != nil {
return nil, fmt.Errorf("dim [%s] is not int", param.Value)
}

if dim != 0 && dim != fieldDim {
return nil, fmt.Errorf("Field %s's dim is [%d], but embeding's dim is [%d]", fieldSchema.Name, fieldDim, dim)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract this dim parsing code into a function in common.go

return nil, err
}

if timeoutSec <= 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider make default timeoutSec a constant in common.go? I see this number and default retry times 3 used in several places.

}
}

func (c *OpenAIEmbeddingClient) Embedding(modelName string, texts []string, dim int, user string, timeoutSec time.Duration) (*EmbeddingResponse, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is largely duplicate with func (c *AzureOpenAIEmbeddingClient) Embedding, can we try share the same logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependency Pull requests that update a dependency file dco-passed DCO check passed. kind/feature Issues related to feature request from users size/XXL Denotes a PR that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants