Skip to content

[OPIK-5152] [SDK] feat: promote search_threads to Opik client API#5739

Open
alexkuzmik wants to merge 5 commits intomainfrom
aliaksandrk/OPIK-5152-promote-threads-methods
Open

[OPIK-5152] [SDK] feat: promote search_threads to Opik client API#5739
alexkuzmik wants to merge 5 commits intomainfrom
aliaksandrk/OPIK-5152-promote-threads-methods

Conversation

@alexkuzmik
Copy link
Collaborator

@alexkuzmik alexkuzmik commented Mar 19, 2026

Details

Promote search_threads from ThreadsClient to the first-class Opik client API, making threads search discoverable without needing get_threads_client(). Also updates the export data documentation to cover threads alongside traces and spans.

Change checklist

  • User facing
  • Documentation update

Issues

  • OPIK-5152

AI-WATERMARK

AI-WATERMARK: yes

  • If yes:
    • Tools: Claude Code
    • Model(s): Claude Opus 4.6
    • Scope: full implementation
    • Human verification: reviewed

Testing

  • Verified import works: cd sdks/python && python -c "from opik.api_objects.opik_client import Opik; print('Import OK')"
  • Existing e2e thread tests cover the underlying ThreadsClient.search_threads() logic (tests/e2e/test_threads.py)
  • The new Opik.search_threads() is a thin delegation wrapper, same pattern as Opik.log_threads_feedback_scores()

Documentation

  • Updated apps/opik-documentation/documentation/fern/docs/tracing/export_data.mdx with a new "Exporting threads" section including examples for filtering by ID, message count, feedback scores, and tags

@alexkuzmik alexkuzmik requested review from a team as code owners March 19, 2026 12:27
@github-actions github-actions bot added documentation Improvements or additions to documentation python Pull requests that update Python code Python SDK labels Mar 19, 2026
@github-actions
Copy link
Contributor

📋 PR Linter Failed

Missing Section. The description is missing the ## Details section.


Missing Section. The description is missing the ## Change checklist section.


Missing Section. The description is missing the ## Issues section.


Missing Section. The description is missing the ## Testing section.


Missing Section. The description is missing the ## Documentation section.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK Unit Tests Results (Python 3.13)

2 254 tests  +31   2 254 ✅ +31   47s ⏱️ +3s
    1 suites ± 0       0 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 3 and adds 34 tests. Note that renamed tests count towards both.
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__invalid_json__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_assertion__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_required_field__returns_failed_results
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelAsync ‑ test_agenerate_string
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_text
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_with_response_format
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_default_max_tokens
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_passes_system_as_top_level_param
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_response_format_uses_parse
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_strips_anthropic_prefix_in_api_call
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_does_not_route_non_anthropic
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_anthropic_prefix
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_bare_claude_name
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK Unit Tests Results (Python 3.11)

2 254 tests  +31   2 254 ✅ +31   45s ⏱️ -2s
    1 suites ± 0       0 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 3 and adds 34 tests. Note that renamed tests count towards both.
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__invalid_json__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_assertion__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_required_field__returns_failed_results
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelAsync ‑ test_agenerate_string
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_text
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_with_response_format
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_default_max_tokens
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_passes_system_as_top_level_param
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_response_format_uses_parse
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_strips_anthropic_prefix_in_api_call
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_does_not_route_non_anthropic
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_anthropic_prefix
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_bare_claude_name
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK Unit Tests Results (Python 3.12)

2 254 tests  +31   2 254 ✅ +31   45s ⏱️ -1s
    1 suites ± 0       0 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 3 and adds 34 tests. Note that renamed tests count towards both.
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__invalid_json__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_assertion__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_required_field__returns_failed_results
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelAsync ‑ test_agenerate_string
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_text
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_with_response_format
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_default_max_tokens
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_passes_system_as_top_level_param
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_response_format_uses_parse
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_strips_anthropic_prefix_in_api_call
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_does_not_route_non_anthropic
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_anthropic_prefix
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_bare_claude_name
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK Unit Tests Results (Python 3.14)

2 254 tests  +31   2 254 ✅ +31   35s ⏱️ -3s
    1 suites ± 0       0 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 3 and adds 34 tests. Note that renamed tests count towards both.
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__invalid_json__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_assertion__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_required_field__returns_failed_results
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelAsync ‑ test_agenerate_string
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_text
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_with_response_format
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_default_max_tokens
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_passes_system_as_top_level_param
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_response_format_uses_parse
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_strips_anthropic_prefix_in_api_call
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_does_not_route_non_anthropic
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_anthropic_prefix
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_bare_claude_name
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK Unit Tests Results (Python 3.10)

2 254 tests  +31   2 254 ✅ +31   45s ⏱️ ±0s
    1 suites ± 0       0 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 3 and adds 34 tests. Note that renamed tests count towards both.
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__invalid_json__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_assertion__returns_failed_results
tests.unit.evaluation.suite_evaluators.test_llm_judge_parsers.TestResponseSchema ‑ test_parse__missing_required_field__returns_failed_results
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelAsync ‑ test_agenerate_string
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_text
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelGenerateString ‑ test_generate_string_with_response_format
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_default_max_tokens
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_passes_system_as_top_level_param
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_response_format_uses_parse
tests.unit.evaluation.models.test_anthropic_chat_model.TestAnthropicChatModelProviderResponse ‑ test_strips_anthropic_prefix_in_api_call
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_does_not_route_non_anthropic
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_anthropic_prefix
tests.unit.evaluation.models.test_anthropic_chat_model.TestFactoryRouting ‑ test_factory_routes_bare_claude_name
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

🌿 Preview your docs: https://opik-preview-27ed2f59-83c2-4f66-a6a5-bde7eda5d75d.docs.buildwithfern.com/docs/opik

No broken links found


📌 Results for commit 1ccdaa3

@github-actions github-actions bot added the tests Including test files, or tests related like configuration. label Mar 19, 2026
Comment on lines +69 to +70
from ..rest_api import client as rest_api_client
from ..rest_api import TraceThread
Copy link
Contributor

Choose a reason for hiding this comment

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

TraceThread is imported via from ..rest_api import TraceThread despite sdks/python/AGENTS.md preferring module-style imports — should we from .. import rest_api and use rest_api.TraceThread?

Finding type: AI Coding Guidelines | Severity: 🟢 Low


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents:

In sdks/python/src/opik/api_objects/opik_client.py around lines 69 to 70, the new code
uses a single-name import `from ..rest_api import TraceThread`, and the `search_threads`
method return annotation and docstrings reference `TraceThread`. Replace the single-name
import with a module-style import (e.g., `from .. import rest_api`) and update the
`search_threads` signature and any other usages to refer to `rest_api.TraceThread`
instead of `TraceThread`. Ensure any type imports list remains correct and run type
checks to confirm no unresolved references remain.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK E2E Tests Results (Python 3.14)

246 tests  ±0   244 ✅ ±0   8m 16s ⏱️ -35s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 1 and adds 1 tests. Note that renamed tests count towards both.
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d05fc-77fe-79b3-bdc5-692ffd22c18a]
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0654-d0d3-745c-a0f0-17bc669856bd]

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK E2E Tests Results (Python 3.11)

246 tests  ±0   244 ✅ ±0   8m 17s ⏱️ -16s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 1 and adds 1 tests. Note that renamed tests count towards both.
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d05fc-2c0d-7d0c-b80c-d96a04e9bb94]
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0656-059a-72b3-b943-2171558ef729]

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK E2E Tests Results (Python 3.13)

246 tests  ±0   244 ✅ +2   8m 49s ⏱️ -55s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌  - 2 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 1 and adds 1 tests. Note that renamed tests count towards both.
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0602-31f6-7c97-990a-2d2ea5e12865]
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0656-615a-76a6-8a63-76666ddd429d]

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK E2E Tests Results (Python 3.10)

246 tests  ±0   244 ✅ ±0   9m 12s ⏱️ +24s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 1 and adds 1 tests. Note that renamed tests count towards both.
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d05fc-ad5f-7db4-8891-7c92fbdbff5e]
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0655-d33e-7da4-b626-735e838804c5]

♻️ This comment has been updated with latest results.

- Address PR review: use trace_thread.TraceThread instead of bare import
- Extract OQL filter reference into shared section for traces/spans/threads
- Simplify search_threads docstring to reference search_traces for full filter details

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Python SDK E2E Tests Results (Python 3.12)

246 tests  ±0   244 ✅ ±0   9m 16s ⏱️ +29s
  1 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2b9a90f. ± Comparison against base commit 0ef43e6.

This pull request removes 1 and adds 1 tests. Note that renamed tests count towards both.
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d05fc-8466-7451-b6ec-7fc9f5949a73]
tests.e2e.test_tracing ‑ test_opik_client__update_trace__happy_flow[None-None-None-None-019d0654-f507-7e2f-9708-a7fb3474bdf6]

♻️ This comment has been updated with latest results.

The previous docstrings and docs incorrectly listed trace columns
(name, input, output, metadata, usage.*, model, provider, etc.) as
available for thread filtering. Threads actually support a narrower
set: id, first_message, last_message, status, duration,
number_of_messages, feedback_scores, tags, and date fields.

Split the shared OQL reference table into per-entity tables (trace,
span, thread) so users see only the columns that actually work.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment on lines 174 to 185
<Tabs>
<Tab value="Python" title="Python">
```python
import opik

client = opik.Opik(
project_name="Default project"
)

# Search for traces where the input contains text
traces = client.search_traces(
filter_string='input contains "Opik"'
)
client = opik.Opik(project_name="Default project")

# Search for traces that were logged after a specific date
# Trace filters
traces = client.search_traces(filter_string='input contains "Opik"')
traces = client.search_traces(filter_string='start_time >= "2024-01-01T00:00:00Z"')

# Search for traces that have a specific tag
traces = client.search_traces(filter_string='tags contains "production"')

# Search for traces based on the number of tokens used
traces = client.search_traces(filter_string='usage.total_tokens > 1000')

# Search for traces based on the model used
traces = client.search_traces(filter_string='metadata.model = "gpt-4o"')
Copy link
Contributor

Choose a reason for hiding this comment

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

search_traces/search_threads snippets lack the required one-line intent, inline comments describing the observable behavior of each filter, and a maintenance note pointing to the canonical/generated example; should we prepend an intent sentence, add inline behavior comments, and include the maintenance-note referencing the generated source before keeping the hand-pasted snippet?

Finding type: Keep docs accurate | Severity: 🟢 Low


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents:

In apps/opik-documentation/documentation/fern/docs/tracing/export_data.mdx around lines
174 to 208, the Python and TypeScript examples for search_traces/search_threads are
missing the required metadata and comments. Prepend each language example with a
single-sentence intent describing what the snippet demonstrates (e.g., “Example: show
filtering traces by start_time, usage, metadata, tags, and feedback presence.”). For
every filter call inside the Python and TypeScript code blocks, add an inline comment on
the same line explaining what observable behavior or trigger the filter demonstrates
(e.g., “# finds traces created after 2024-01-01” or “// finds traces with
production tag”). Finally, add a short maintenance note directly after each code block
that references the canonical/generated example source (include the repository path or
URL, the update cadence, and the owning team), e.g. “Maintenance: canonical snippet
generated from <repo/path-or-URL>, regenerated daily, owned by <team-name>.” Make
these edits so the examples meet the documentation reviewer's requirements for intent,
observability comments, and maintenance provenance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Python SDK python Pull requests that update Python code tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant