Skip to content
Merged
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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
lint:
name: lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

Expand All @@ -33,7 +32,6 @@ jobs:
test:
name: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.2.0"
".": "0.2.1"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 32
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/mixedbread%2Fmixedbread-82c2c1c322149cd73b2e8e45f475919b941752a89e74464ccecd1aee9352e9be.yml
openapi_spec_hash: a47fe4cb39ee0cb74ee5888de2f0a5e1
config_hash: 6d1076e161e84bae54e1b0df1015d37e
config_hash: 6a7c1faa96b022a6959d720d7957eade
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

## 0.2.1 (2025-04-12)

Full Changelog: [v0.2.0...v0.2.1](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.2.0...v0.2.1)

### Bug Fixes

* **perf:** skip traversing types for NotGiven values ([77ca84f](https://github.com/mixedbread-ai/mixedbread-python/commit/77ca84fd479fdc4bb8e097ce77717fb7d6351974))


### Chores

* **internal:** expand CI branch coverage ([a3c7c80](https://github.com/mixedbread-ai/mixedbread-python/commit/a3c7c80a2e913a3f53e95eb7c85637f9fbaed2b2))
* **internal:** reduce CI branch coverage ([bf50b05](https://github.com/mixedbread-ai/mixedbread-python/commit/bf50b0586e3b716afe2e09ff19b0ddf6eb835db1))
* **internal:** slight transform perf improvement ([#196](https://github.com/mixedbread-ai/mixedbread-python/issues/196)) ([65548f9](https://github.com/mixedbread-ai/mixedbread-python/commit/65548f934aae308b4ae4f44158d789c74436501a))
* slight wording improvement in README ([#198](https://github.com/mixedbread-ai/mixedbread-python/issues/198)) ([5bbfa5a](https://github.com/mixedbread-ai/mixedbread-python/commit/5bbfa5acac3c1d9fd6c476f7e1ebf44ee317cacb))
* **tests:** improve enum examples ([#197](https://github.com/mixedbread-ai/mixedbread-python/issues/197)) ([662d9f5](https://github.com/mixedbread-ai/mixedbread-python/commit/662d9f5cfdb106d43b9d55fc85bc5b2ea78af7c4))

## 0.2.0 (2025-04-08)

Full Changelog: [v0.1.0...v0.2.0](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.1.0...v0.2.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ print(vector_store.expires_after)

## File uploads

Request parameters that correspond to file uploads can be passed as `bytes`, a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.

```python
from pathlib import Path
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "mixedbread"
version = "0.2.0"
version = "0.2.1"
description = "The official Python library for the Mixedbread API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
33 changes: 33 additions & 0 deletions src/mixedbread/_utils/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ._utils import (
is_list,
is_given,
is_mapping,
is_iterable,
)
Expand Down Expand Up @@ -142,6 +143,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
return key


def _no_transform_needed(annotation: type) -> bool:
return annotation == float or annotation == int


def _transform_recursive(
data: object,
*,
Expand Down Expand Up @@ -184,6 +189,15 @@ def _transform_recursive(
return cast(object, data)

inner_type = extract_type_arg(stripped_type, 0)
if _no_transform_needed(inner_type):
# for some types there is no need to transform anything, so we can get a small
# perf boost from skipping that work.
#
# but we still need to convert to a list to ensure the data is json-serializable
if is_list(data):
return data
return list(data)

return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]

if is_union_type(stripped_type):
Expand Down Expand Up @@ -245,6 +259,11 @@ def _transform_typeddict(
result: dict[str, object] = {}
annotations = get_type_hints(expected_type, include_extras=True)
for key, value in data.items():
if not is_given(value):
# we don't need to include `NotGiven` values here as they'll
# be stripped out before the request is sent anyway
continue

type_ = annotations.get(key)
if type_ is None:
# we do not have a type annotation for this field, leave it as is
Expand Down Expand Up @@ -332,6 +351,15 @@ async def _async_transform_recursive(
return cast(object, data)

inner_type = extract_type_arg(stripped_type, 0)
if _no_transform_needed(inner_type):
# for some types there is no need to transform anything, so we can get a small
# perf boost from skipping that work.
#
# but we still need to convert to a list to ensure the data is json-serializable
if is_list(data):
return data
return list(data)

return [await _async_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]

if is_union_type(stripped_type):
Expand Down Expand Up @@ -393,6 +421,11 @@ async def _async_transform_typeddict(
result: dict[str, object] = {}
annotations = get_type_hints(expected_type, include_extras=True)
for key, value in data.items():
if not is_given(value):
# we don't need to include `NotGiven` values here as they'll
# be stripped out before the request is sent anyway
continue

type_ = annotations.get(key)
if type_ is None:
# we do not have a type annotation for this field, leave it as is
Expand Down
2 changes: 1 addition & 1 deletion src/mixedbread/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "mixedbread"
__version__ = "0.2.0" # x-release-please-version
__version__ = "0.2.1" # x-release-please-version
24 changes: 12 additions & 12 deletions tests/api_resources/test_vector_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_method_question_answering_with_all_params(self, client: Mixedbread) ->
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -252,7 +252,7 @@ def test_method_question_answering_with_all_params(self, client: Mixedbread) ->
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -264,7 +264,7 @@ def test_method_question_answering_with_all_params(self, client: Mixedbread) ->
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_method_search_with_all_params(self, client: Mixedbread) -> None:
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -340,7 +340,7 @@ def test_method_search_with_all_params(self, client: Mixedbread) -> None:
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -352,7 +352,7 @@ def test_method_search_with_all_params(self, client: Mixedbread) -> None:
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand Down Expand Up @@ -617,7 +617,7 @@ async def test_method_question_answering_with_all_params(self, async_client: Asy
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -629,7 +629,7 @@ async def test_method_question_answering_with_all_params(self, async_client: Asy
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -641,7 +641,7 @@ async def test_method_question_answering_with_all_params(self, async_client: Asy
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand Down Expand Up @@ -705,7 +705,7 @@ async def test_method_search_with_all_params(self, async_client: AsyncMixedbread
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -717,7 +717,7 @@ async def test_method_search_with_all_params(self, async_client: AsyncMixedbread
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -729,7 +729,7 @@ async def test_method_search_with_all_params(self, async_client: AsyncMixedbread
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand Down
12 changes: 6 additions & 6 deletions tests/api_resources/vector_stores/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def test_method_search_with_all_params(self, client: Mixedbread) -> None:
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -251,7 +251,7 @@ def test_method_search_with_all_params(self, client: Mixedbread) -> None:
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -263,7 +263,7 @@ def test_method_search_with_all_params(self, client: Mixedbread) -> None:
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand Down Expand Up @@ -529,7 +529,7 @@ async def test_method_search_with_all_params(self, async_client: AsyncMixedbread
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -541,7 +541,7 @@ async def test_method_search_with_all_params(self, async_client: AsyncMixedbread
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand All @@ -553,7 +553,7 @@ async def test_method_search_with_all_params(self, async_client: AsyncMixedbread
{
"key": "price",
"value": "100",
"operator": "eq",
"operator": "gt",
},
{
"key": "color",
Expand Down
21 changes: 20 additions & 1 deletion tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pytest

from mixedbread._types import Base64FileInput
from mixedbread._types import NOT_GIVEN, Base64FileInput
from mixedbread._utils import (
PropertyInfo,
transform as _transform,
Expand Down Expand Up @@ -432,3 +432,22 @@ async def test_base64_file_input(use_async: bool) -> None:
assert await transform({"foo": io.BytesIO(b"Hello, world!")}, TypedDictBase64Input, use_async) == {
"foo": "SGVsbG8sIHdvcmxkIQ=="
} # type: ignore[comparison-overlap]


@parametrize
@pytest.mark.asyncio
async def test_transform_skipping(use_async: bool) -> None:
# lists of ints are left as-is
data = [1, 2, 3]
assert await transform(data, List[int], use_async) is data

# iterables of ints are converted to a list
data = iter([1, 2, 3])
assert await transform(data, Iterable[int], use_async) == [1, 2, 3]


@parametrize
@pytest.mark.asyncio
async def test_strips_notgiven(use_async: bool) -> None:
assert await transform({"foo_bar": "bar"}, Foo1, use_async) == {"fooBar": "bar"}
assert await transform({"foo_bar": NOT_GIVEN}, Foo1, use_async) == {}
Loading