Files
OpenViking/sdk/go/retrieval.go
T
9eac8a6d3d feat(sdk): sync go/ts/python SDKs with server find/search, recall, an… (#3737)
* feat(sdk): sync go/ts/python SDKs with server find/search, recall, and admin changes

Server-side changes recently landed that the language SDKs had drifted from:

- find/search results now return `tags` and no longer return
  `category`/`match_reason`/`relations`/`overview` (#3730). Go's strict
  struct was the only one broken; update MatchedContext accordingly.
- new admin endpoints for agent-evolution and per-account settings (#3695).
- public `search/recall` endpoint was missing from all SDKs.

Changes:
- python: add `level`/`since`/`until`/`time_field` to find/search; add an
  `extra` escape hatch to find/search/add_resource/write/batch_write so new
  server fields can be passed without an SDK bump (only forwarded when set,
  preserving `level=0`); add `recall` and the four admin methods.
- go: fix MatchedContext (add Tags, drop removed fields), add Recall and the
  four admin methods.
- typescript: type MatchedContext/FindResult, add RecallOptions, add `recall`
  and the four admin methods.

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

feat(sdk): unify options APIs and sync latest server interfaces

- migrate complex Python SDK calls to typed options dictionaries
- add dedicated context search and consistent extra-field handling
- align Go and TypeScript options with omission-aware serialization
- support session config, event tags, Agent Evolution date filters,
  OpenViking Assets, batch write, downloads, and create_parent
- refresh SDK tests and examples across all three languages

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): address options API review findings

- fix Go session extra merging and Python message precedence
- adapt LangChain calls to the Python options API
- migrate repository examples, tests, and documentation

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): complete options migration and message parity

- migrate remaining Python SDK benchmarks to options dictionaries
- normalize empty parts consistently for single and batch messages
- add regression guards for repository SDK call sites

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): align reindex options after main rebase

- preserve reindex tags in Python typed options
- add reindex extra support for Go and TypeScript
- reject official fields passed through extra across SDKs

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

feat(sdk): support legacy keyword options

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

docs(sdk): use explicit Python SDK arguments

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): support set tags extra options

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): expose Go add resource options

Expose AddType and ProcessingMode through Go AddResourceOptions and serialize them to the resources API. Add a regression test covering the resulting request payload.

Co-authored-by: TRAE CLI <noreply@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>

feat(sdk): flatten core Python client options

Co-authored-by: TRAE CLI <traecli@bytedance.com>

docs(sdk): align Python examples with flattened options

Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): preserve core API compatibility

Co-authored-by: TRAE CLI <traecli@bytedance.com>

refactor(python-sdk): move resource hints to options

Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): align resource option callers

Co-authored-by: TRAE CLI <traecli@bytedance.com>

test(sdk): cover recursive reindex forwarding

Co-authored-by: TRAE CLI <traecli@bytedance.com>

fix(sdk): preserve Go options compatibility

Co-authored-by: TRAE CLI <traecli@bytedance.com>

feat(python-sdk): expose message peer id

Co-authored-by: TRAE CLI <traecli@bytedance.com>

test(python-sdk): consolidate options coverage

Co-authored-by: TRAE CLI <traecli@bytedance.com>

feat(python-sdk): add parts and flatten image search

Co-authored-by: TRAE CLI <traecli@bytedance.com>

* docs(sdk): align Python call examples

Co-authored-by: TRAE CLI <traecli@bytedance.com>

---------

Co-authored-by: TRAE CLI <traecli@bytedance.com>
Co-authored-by: Qin Haojie <qinhaojie.exe@bytedance.com>
2026-08-24 14:09:11 +08:00

191 lines
5.7 KiB
Go

package openviking
import (
"context"
"net/http"
)
// Find performs semantic search without session context.
func (c *Client) Find(ctx context.Context, queryText string, opts *FindOptions) (*FindResult, error) {
if opts == nil {
opts = &FindOptions{}
}
limit := opts.Limit
if limit == 0 {
limit = 10
}
if opts.NodeLimit != nil {
limit = *opts.NodeLimit
}
imageURL, err := normalizeImageInput(opts.Image)
if err != nil {
return nil, err
}
payload := map[string]any{"query": queryText}
if opts.TargetURI != nil {
payload["target_uri"] = normalizeTarget(opts.TargetURI)
}
payload["limit"] = limit
setString(payload, "image_url", imageURL)
setAny(payload, "score_threshold", opts.ScoreThreshold)
setAny(payload, "filter", opts.Filter)
setAny(payload, "context_type", opts.ContextType)
setAny(payload, "include_provenance", opts.IncludeProvenance)
setString(payload, "since", opts.Since)
setString(payload, "until", opts.Until)
setString(payload, "time_field", opts.TimeField)
if opts.Level != nil {
payload["level"] = opts.Level
}
if opts.Tags != nil {
payload["tags"] = opts.Tags
}
setAny(payload, "telemetry", opts.Telemetry)
if err := mergeExtra(payload, opts.Extra); err != nil {
return nil, err
}
var result FindResult
err = c.doJSON(ctx, http.MethodPost, "/api/v1/search/find", nil, payload, &result)
return &result, err
}
// Search performs semantic search with optional session context.
func (c *Client) Search(ctx context.Context, queryText string, opts *SearchOptions) (*FindResult, error) {
if opts == nil {
opts = &SearchOptions{}
}
limit := opts.Limit
if limit == 0 {
limit = 10
}
if opts.NodeLimit != nil {
limit = *opts.NodeLimit
}
imageURL, err := normalizeImageInput(opts.Image)
if err != nil {
return nil, err
}
payload := map[string]any{"query": queryText}
if opts.TargetURI != nil {
payload["target_uri"] = normalizeTarget(opts.TargetURI)
}
payload["limit"] = limit
setString(payload, "image_url", imageURL)
setString(payload, "session_id", opts.SessionID)
setAny(payload, "score_threshold", opts.ScoreThreshold)
setAny(payload, "filter", opts.Filter)
setAny(payload, "context_type", opts.ContextType)
setAny(payload, "include_provenance", opts.IncludeProvenance)
setString(payload, "since", opts.Since)
setString(payload, "until", opts.Until)
setString(payload, "time_field", opts.TimeField)
if opts.Level != nil {
payload["level"] = opts.Level
}
if opts.Tags != nil {
payload["tags"] = opts.Tags
}
setAny(payload, "telemetry", opts.Telemetry)
if err := mergeExtra(payload, opts.Extra); err != nil {
return nil, err
}
var result FindResult
err = c.doJSON(ctx, http.MethodPost, "/api/v1/search/search", nil, payload, &result)
return &result, err
}
// SearchContext assembles injection-ready context on the server.
func (c *Client) SearchContext(ctx context.Context, query string, opts *SearchContextOptions) (*SearchContextResult, error) {
if opts == nil {
opts = &SearchContextOptions{}
}
payload := map[string]any{
"query": query,
"mode": "context",
}
imageURL, err := normalizeImageInput(opts.Image)
if err != nil {
return nil, err
}
setString(payload, "image_url", imageURL)
setString(payload, "session_id", opts.SessionID)
setAny(payload, "limit", opts.Limit)
setAny(payload, "node_limit", opts.NodeLimit)
setAny(payload, "score_threshold", opts.ScoreThreshold)
setAny(payload, "filter", opts.Filter)
setAny(payload, "context_type", opts.ContextType)
setAny(payload, "include_provenance", opts.IncludeProvenance)
if opts.Tags != nil {
payload["tags"] = opts.Tags
}
setString(payload, "since", opts.Since)
setString(payload, "until", opts.Until)
setString(payload, "time_field", opts.TimeField)
setString(payload, "query_expansion", opts.QueryExpansion)
setAny(payload, "max_tokens", opts.MaxTokens)
if opts.Quotas != nil {
payload["quotas"] = opts.Quotas
}
setString(payload, "purpose", opts.Purpose)
setAny(payload, "detail", opts.Detail)
setAny(payload, "dedup_turns", opts.DedupTurns)
if opts.ExcludeURIs != nil {
payload["exclude_uris"] = opts.ExcludeURIs
}
setString(payload, "peer_scope", opts.PeerScope)
setAny(payload, "other_peer_penalty", opts.OtherPeerPenalty)
setAny(payload, "rewrite", opts.Rewrite)
setAny(payload, "rewrite_max_bullets", opts.RewriteMaxBullets)
setAny(payload, "telemetry", opts.Telemetry)
if err := mergeExtra(payload, opts.Extra); err != nil {
return nil, err
}
var result SearchContextResult
err = c.doJSON(ctx, http.MethodPost, "/api/v1/search/search", nil, payload, &result)
return &result, err
}
// Grep searches file content by pattern.
func (c *Client) Grep(ctx context.Context, uri, pattern string, opts *GrepOptions) (map[string]any, error) {
if opts == nil {
opts = &GrepOptions{}
}
payload := map[string]any{
"uri": NormalizeURI(uri),
"pattern": pattern,
"case_insensitive": opts.CaseInsensitive,
}
if opts.NodeLimit != nil {
payload["node_limit"] = *opts.NodeLimit
}
if opts.LevelLimit != nil {
payload["level_limit"] = *opts.LevelLimit
}
if opts.ExcludeURI != "" {
payload["exclude_uri"] = NormalizeURI(opts.ExcludeURI)
}
var result map[string]any
err := c.doJSON(ctx, http.MethodPost, "/api/v1/search/grep", nil, payload, &result)
return result, err
}
// Glob finds files by glob pattern.
func (c *Client) Glob(ctx context.Context, pattern string, uri string, opts *GlobOptions) (map[string]any, error) {
if opts == nil {
opts = &GlobOptions{}
}
if uri == "" {
uri = "viking://"
}
payload := map[string]any{
"pattern": pattern,
"uri": NormalizeURI(uri),
}
if opts.NodeLimit != nil {
payload["node_limit"] = *opts.NodeLimit
}
var result map[string]any
err := c.doJSON(ctx, http.MethodPost, "/api/v1/search/glob", nil, payload, &result)
return result, err
}