-
Notifications
You must be signed in to change notification settings - Fork 81
OAS-11787: Add Vector index feature and it's related testcases #725
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
Open
bluepal-prasanthi-moparthi
wants to merge
2
commits into
master
Choose a base branch
from
feature/OAS-11787-vector-index-stored-values-and-index-hint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ package arangodb | |||
| import ( | ||||
| "context" | ||||
| "encoding/json" | ||||
| "fmt" | ||||
| "net/http" | ||||
| "net/url" | ||||
|
|
||||
|
|
@@ -306,23 +307,111 @@ func (i *IndexResponse) UnmarshalJSON(data []byte) error { | |||
| i.Name = respSimple.Name | ||||
| i.Type = respSimple.Type | ||||
|
|
||||
| if respSimple.Type == InvertedIndexType { | ||||
| switch respSimple.Type { | ||||
| case InvertedIndexType: | ||||
| result := responseInvertedIndex{} | ||||
| if err := json.Unmarshal(data, &result); err != nil { | ||||
| return err | ||||
| } | ||||
|
|
||||
| i.IndexSharedOptions = result.IndexSharedOptions | ||||
| i.InvertedIndex = &result.InvertedIndexOptions | ||||
| } else { | ||||
| case VectorIndexType: | ||||
| result := responseVectorIndex{} | ||||
| if err := json.Unmarshal(data, &result); err != nil { | ||||
| return err | ||||
| } | ||||
| i.IndexSharedOptions = result.IndexSharedOptions | ||||
| i.VectorIndex = result.Params | ||||
| default: | ||||
| result := responseIndex{} | ||||
| if err := json.Unmarshal(data, &result); err != nil { | ||||
| return err | ||||
| } | ||||
|
|
||||
| i.IndexSharedOptions = result.IndexSharedOptions | ||||
| i.RegularIndex = &result.IndexOptions | ||||
| } | ||||
| return nil | ||||
| } | ||||
|
|
||||
| func (p *VectorParams) validate() error { | ||||
| if p == nil { | ||||
| return errors.New("params must be provided for vector index") | ||||
| } | ||||
|
|
||||
| if p.Dimension == nil || *p.Dimension <= 0 { | ||||
| return errors.New("params.Dimension must be provided and greater than zero for vector index") | ||||
| } | ||||
|
|
||||
| if p.Metric == nil { | ||||
| return errors.New("params.Metric must be provided for vector index") | ||||
| } | ||||
|
|
||||
| switch *p.Metric { | ||||
| case VectorMetricCosine, VectorMetricL2, VectorMetricInnerProduct: | ||||
| // valid | ||||
| default: | ||||
| return errors.New("params.Metric must be one of 'cosine', 'l2', or 'innerProduct' for vector index") | ||||
| } | ||||
|
|
||||
| if p.NLists != nil && *p.NLists <= 0 { | ||||
| return errors.New("params.NLists must be greater than zero for vector index") | ||||
| } | ||||
|
|
||||
| return nil | ||||
| } | ||||
|
|
||||
| func (c *collectionIndexes) EnsureVectorIndex( | ||||
| ctx context.Context, | ||||
| fields []string, | ||||
| params *VectorParams, | ||||
| options *CreateVectorIndexOptions, | ||||
| ) (IndexResponse, bool, error) { | ||||
|
|
||||
| if len(fields) != 1 { | ||||
| return IndexResponse{}, false, errors.New("vector index requires exactly one field") | ||||
| } | ||||
| if err := params.validate(); err != nil { | ||||
| return IndexResponse{}, false, err | ||||
| } | ||||
|
|
||||
| reqData := struct { | ||||
| Type IndexType `json:"type"` | ||||
| Fields []string `json:"fields"` | ||||
| Params *VectorParams `json:"params"` | ||||
| *CreateVectorIndexOptions | ||||
| }{ | ||||
| Type: VectorIndexType, | ||||
| Fields: fields, | ||||
| Params: params, | ||||
| CreateVectorIndexOptions: options, | ||||
| } | ||||
|
|
||||
| result := responseVectorIndex{} | ||||
| fmt.Printf("reqData: %+v", reqData) | ||||
|
||||
| fmt.Printf("reqData: %+v", reqData) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states that NLists is a required field that must be present, but the validation logic treats it as optional (only validates if non-nil). Either update the documentation to reflect that NLists is optional, or make the validation enforce it as required.