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

qdrant: add wait option when adding documents #990

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions vectorstores/qdrant/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

const (
defaultContentKey = "content"
defaultContentKey = "content"
defaultWaitForInsert = true
)

// ErrInvalidOptions is returned when the options given are invalid.
Expand Down Expand Up @@ -56,9 +57,18 @@ func WithContentKey(contentKey string) Option {
}
}

// WithWaitForInsert returns an Option for setting whether to wait for the insert to complete.
// Optional. Defaults to true.
func WithWaitForInsert(wait bool) Option {
return func(p *Store) {
p.waitForInsert = wait
}
}

func applyClientOptions(opts ...Option) (Store, error) {
o := &Store{
contentKey: defaultContentKey,
contentKey: defaultContentKey,
waitForInsert: defaultWaitForInsert,
}

for _, opt := range opts {
Expand Down
1 change: 1 addition & 0 deletions vectorstores/qdrant/qdrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Store struct {
qdrantURL url.URL
apiKey string
contentKey string
waitForInsert bool
}

var _ vectorstores.VectorStore = Store{}
Expand Down
10 changes: 7 additions & 3 deletions vectorstores/qdrant/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ func (s Store) upsertPoints(
},
}

url := baseURL.JoinPath("collections", s.collectionName, "points")
upsertURL := baseURL.JoinPath("collections", s.collectionName, "points")
queryParams := url.Values{}
queryParams.Add("wait", fmt.Sprintf("%t", s.waitForInsert))
upsertURL.RawQuery = queryParams.Encode()

body,
status,
err := DoRequest(
ctx, *url,
ctx, *upsertURL,
s.apiKey,
http.MethodPut,
payload,
Expand Down Expand Up @@ -134,7 +138,7 @@ func DoRequest(ctx context.Context,
}
body := bytes.NewReader(payloadBytes)

req, err := http.NewRequestWithContext(ctx, method, url.String()+"?wait=true", body)
req, err := http.NewRequestWithContext(ctx, method, url.String(), body)
if err != nil {
return nil, 0, err
}
Expand Down
Loading