diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c6075a38..da1c1d13 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -19,7 +19,7 @@ jobs:
timeout-minutes: 10
name: lint
runs-on: ${{ github.repository == 'stainless-sdks/mixedbread-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
- if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
+ if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
steps:
- uses: actions/checkout@v6
@@ -38,7 +38,7 @@ jobs:
run: ./scripts/lint
build:
- if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
+ if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
timeout-minutes: 10
name: build
permissions:
diff --git a/.gitignore b/.gitignore
index 95ceb189..3824f4c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.prism.log
+.stdy.log
_dev
__pycache__
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index dd7ced1c..26b1ce24 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.49.0"
+ ".": "0.50.0"
}
\ No newline at end of file
diff --git a/.stats.yml b/.stats.yml
index 4bb5a628..d24ae9f1 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,4 +1,4 @@
-configured_endpoints: 56
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/mixedbread%2Fmixedbread-3daf4d41b24950791a70688527c10dea9e201d304b8d6432b3acfa50e33e0805.yml
-openapi_spec_hash: 1ecaa0f38266f1c5d1da8fb2e9ef651a
+configured_endpoints: 55
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/mixedbread%2Fmixedbread-9e9ff254deac02bfc433cce6198b88cfe65fc1e8114140eb0c9f15633f64715a.yml
+openapi_spec_hash: 3969b885ff63816924d234ff04592801
config_hash: c32ffa6858a02d7f23f6f3dda0b461ed
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 449aae02..56566696 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,37 @@
# Changelog
+## 0.50.0 (2026-04-01)
+
+Full Changelog: [v0.49.0...v0.50.0](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.49.0...v0.50.0)
+
+### Features
+
+* **api:** api update ([4ad956c](https://github.com/mixedbread-ai/mixedbread-python/commit/4ad956c1b52e6a08dc44958cb331451f5bec75af))
+* **api:** api update ([a24ebe9](https://github.com/mixedbread-ai/mixedbread-python/commit/a24ebe9e241e075c2958cefecfe9e972a5bcd55f))
+* **internal:** implement indices array format for query and form serialization ([e52e262](https://github.com/mixedbread-ai/mixedbread-python/commit/e52e262bd9acd3caa49cf9ba08a29b260b722bf0))
+
+
+### Bug Fixes
+
+* sanitize endpoint path params ([7d519be](https://github.com/mixedbread-ai/mixedbread-python/commit/7d519be7f4ea6b2ce11c9915ee1ac903ebb97cea))
+
+
+### Chores
+
+* **ci:** skip lint on metadata-only changes ([a3ec133](https://github.com/mixedbread-ai/mixedbread-python/commit/a3ec133b88d1a70a066c17e29dd2ebd5decffb25))
+* **internal:** update gitignore ([cf3aa78](https://github.com/mixedbread-ai/mixedbread-python/commit/cf3aa78ec44036bbedce95735ee7ab43cc4d566a))
+* **tests:** bump steady to v0.19.4 ([d6e32d5](https://github.com/mixedbread-ai/mixedbread-python/commit/d6e32d5abe0e137375ea79373033c07057b22c83))
+* **tests:** bump steady to v0.19.5 ([59351b9](https://github.com/mixedbread-ai/mixedbread-python/commit/59351b9dcb0eaf2578c985c80a0501d610ff357d))
+* **tests:** bump steady to v0.19.6 ([ac0e7ac](https://github.com/mixedbread-ai/mixedbread-python/commit/ac0e7acc35384a0ae9f78040b60bce03f8258d81))
+* **tests:** bump steady to v0.19.7 ([839ee9c](https://github.com/mixedbread-ai/mixedbread-python/commit/839ee9c7c60749ae03a125f84e87a7be9365daac))
+* **tests:** bump steady to v0.20.1 ([31e2274](https://github.com/mixedbread-ai/mixedbread-python/commit/31e2274bfe265fbebae02c86beae2f575f9b7b18))
+* **tests:** bump steady to v0.20.2 ([6879b15](https://github.com/mixedbread-ai/mixedbread-python/commit/6879b159d830df5df58696899c7551c709595ed4))
+
+
+### Refactors
+
+* **tests:** switch from prism to steady ([cc454cf](https://github.com/mixedbread-ai/mixedbread-python/commit/cc454cfbe5752c8e439361c52fb31d2d2b14180d))
+
## 0.49.0 (2026-03-19)
Full Changelog: [v0.48.0...v0.49.0](https://github.com/mixedbread-ai/mixedbread-python/compare/v0.48.0...v0.49.0)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ed6fa9a1..21b21b70 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -85,7 +85,7 @@ $ pip install ./path-to-wheel-file.whl
## Running tests
-Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
+Most tests require you to [set up a mock server](https://github.com/dgellow/steady) against the OpenAPI spec to run the tests.
```sh
$ ./scripts/mock
diff --git a/api.md b/api.md
index 53e03831..3efedf4e 100644
--- a/api.md
+++ b/api.md
@@ -60,14 +60,7 @@ Methods:
Types:
```python
-from mixedbread.types.stores import (
- ScoredStoreFile,
- StoreFileStatus,
- StoreFile,
- FileListResponse,
- FileDeleteResponse,
- FileSearchResponse,
-)
+from mixedbread.types.stores import StoreFileStatus, StoreFile, FileListResponse, FileDeleteResponse
```
Methods:
@@ -77,7 +70,6 @@ Methods:
- client.stores.files.update(file_identifier, \*, store_identifier, \*\*params) -> StoreFile
- client.stores.files.list(store_identifier, \*\*params) -> FileListResponse
- client.stores.files.delete(file_identifier, \*, store_identifier) -> FileDeleteResponse
-- client.stores.files.search(\*\*params) -> FileSearchResponse
# Parsing
diff --git a/pyproject.toml b/pyproject.toml
index d39892a9..1dc4f151 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "mixedbread"
-version = "0.49.0"
+version = "0.50.0"
description = "The official Python library for the Mixedbread API"
dynamic = ["readme"]
license = "Apache-2.0"
diff --git a/scripts/mock b/scripts/mock
index bcf3b392..7c58865f 100755
--- a/scripts/mock
+++ b/scripts/mock
@@ -19,34 +19,34 @@ fi
echo "==> Starting mock server with URL ${URL}"
-# Run prism mock on the given spec
+# Run steady mock on the given spec
if [ "$1" == "--daemon" ]; then
# Pre-install the package so the download doesn't eat into the startup timeout
- npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism --version
+ npm exec --package=@stdy/cli@0.20.2 -- steady --version
- npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL" &> .prism.log &
+ npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=repeat --validator-form-array-format=repeat --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &
- # Wait for server to come online (max 30s)
+ # Wait for server to come online via health endpoint (max 30s)
echo -n "Waiting for server"
attempts=0
- while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
+ while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do
+ if ! kill -0 $! 2>/dev/null; then
+ echo
+ cat .stdy.log
+ exit 1
+ fi
attempts=$((attempts + 1))
if [ "$attempts" -ge 300 ]; then
echo
- echo "Timed out waiting for Prism server to start"
- cat .prism.log
+ echo "Timed out waiting for Steady server to start"
+ cat .stdy.log
exit 1
fi
echo -n "."
sleep 0.1
done
- if grep -q "✖ fatal" ".prism.log"; then
- cat .prism.log
- exit 1
- fi
-
echo
else
- npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock "$URL"
+ npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=repeat --validator-form-array-format=repeat --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
fi
diff --git a/scripts/test b/scripts/test
index dbeda2d2..87cdeac2 100755
--- a/scripts/test
+++ b/scripts/test
@@ -9,8 +9,8 @@ GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
-function prism_is_running() {
- curl --silent "http://localhost:4010" >/dev/null 2>&1
+function steady_is_running() {
+ curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1
}
kill_server_on_port() {
@@ -25,7 +25,7 @@ function is_overriding_api_base_url() {
[ -n "$TEST_API_BASE_URL" ]
}
-if ! is_overriding_api_base_url && ! prism_is_running ; then
+if ! is_overriding_api_base_url && ! steady_is_running ; then
# When we exit this script, make sure to kill the background mock server process
trap 'kill_server_on_port 4010' EXIT
@@ -36,19 +36,19 @@ fi
if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
-elif ! prism_is_running ; then
- echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
+elif ! steady_is_running ; then
+ echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Steady server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
- echo -e "spec to the prism command:"
+ echo -e "spec to the steady command:"
echo
- echo -e " \$ ${YELLOW}npm exec --package=@stainless-api/prism-cli@5.15.0 -- prism mock path/to/your.openapi.yml${NC}"
+ echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.20.2 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=repeat --validator-form-array-format=repeat --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}"
echo
exit 1
else
- echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}"
+ echo -e "${GREEN}✔ Mock steady server is running with your OpenAPI spec${NC}"
echo
fi
diff --git a/src/mixedbread/_qs.py b/src/mixedbread/_qs.py
index ada6fd3f..de8c99bc 100644
--- a/src/mixedbread/_qs.py
+++ b/src/mixedbread/_qs.py
@@ -101,7 +101,10 @@ def _stringify_item(
items.extend(self._stringify_item(key, item, opts))
return items
elif array_format == "indices":
- raise NotImplementedError("The array indices format is not supported yet")
+ items = []
+ for i, item in enumerate(value):
+ items.extend(self._stringify_item(f"{key}[{i}]", item, opts))
+ return items
elif array_format == "brackets":
items = []
key = key + "[]"
diff --git a/src/mixedbread/_utils/__init__.py b/src/mixedbread/_utils/__init__.py
index dc64e29a..10cb66d2 100644
--- a/src/mixedbread/_utils/__init__.py
+++ b/src/mixedbread/_utils/__init__.py
@@ -1,3 +1,4 @@
+from ._path import path_template as path_template
from ._sync import asyncify as asyncify
from ._proxy import LazyProxy as LazyProxy
from ._utils import (
diff --git a/src/mixedbread/_utils/_path.py b/src/mixedbread/_utils/_path.py
new file mode 100644
index 00000000..4d6e1e4c
--- /dev/null
+++ b/src/mixedbread/_utils/_path.py
@@ -0,0 +1,127 @@
+from __future__ import annotations
+
+import re
+from typing import (
+ Any,
+ Mapping,
+ Callable,
+)
+from urllib.parse import quote
+
+# Matches '.' or '..' where each dot is either literal or percent-encoded (%2e / %2E).
+_DOT_SEGMENT_RE = re.compile(r"^(?:\.|%2[eE]){1,2}$")
+
+_PLACEHOLDER_RE = re.compile(r"\{(\w+)\}")
+
+
+def _quote_path_segment_part(value: str) -> str:
+ """Percent-encode `value` for use in a URI path segment.
+
+ Considers characters not in `pchar` set from RFC 3986 §3.3 to be unsafe.
+ https://datatracker.ietf.org/doc/html/rfc3986#section-3.3
+ """
+ # quote() already treats unreserved characters (letters, digits, and -._~)
+ # as safe, so we only need to add sub-delims, ':', and '@'.
+ # Notably, unlike the default `safe` for quote(), / is unsafe and must be quoted.
+ return quote(value, safe="!$&'()*+,;=:@")
+
+
+def _quote_query_part(value: str) -> str:
+ """Percent-encode `value` for use in a URI query string.
+
+ Considers &, = and characters not in `query` set from RFC 3986 §3.4 to be unsafe.
+ https://datatracker.ietf.org/doc/html/rfc3986#section-3.4
+ """
+ return quote(value, safe="!$'()*+,;:@/?")
+
+
+def _quote_fragment_part(value: str) -> str:
+ """Percent-encode `value` for use in a URI fragment.
+
+ Considers characters not in `fragment` set from RFC 3986 §3.5 to be unsafe.
+ https://datatracker.ietf.org/doc/html/rfc3986#section-3.5
+ """
+ return quote(value, safe="!$&'()*+,;=:@/?")
+
+
+def _interpolate(
+ template: str,
+ values: Mapping[str, Any],
+ quoter: Callable[[str], str],
+) -> str:
+ """Replace {name} placeholders in `template`, quoting each value with `quoter`.
+
+ Placeholder names are looked up in `values`.
+
+ Raises:
+ KeyError: If a placeholder is not found in `values`.
+ """
+ # re.split with a capturing group returns alternating
+ # [text, name, text, name, ..., text] elements.
+ parts = _PLACEHOLDER_RE.split(template)
+
+ for i in range(1, len(parts), 2):
+ name = parts[i]
+ if name not in values:
+ raise KeyError(f"a value for placeholder {{{name}}} was not provided")
+ val = values[name]
+ if val is None:
+ parts[i] = "null"
+ elif isinstance(val, bool):
+ parts[i] = "true" if val else "false"
+ else:
+ parts[i] = quoter(str(values[name]))
+
+ return "".join(parts)
+
+
+def path_template(template: str, /, **kwargs: Any) -> str:
+ """Interpolate {name} placeholders in `template` from keyword arguments.
+
+ Args:
+ template: The template string containing {name} placeholders.
+ **kwargs: Keyword arguments to interpolate into the template.
+
+ Returns:
+ The template with placeholders interpolated and percent-encoded.
+
+ Safe characters for percent-encoding are dependent on the URI component.
+ Placeholders in path and fragment portions are percent-encoded where the `segment`
+ and `fragment` sets from RFC 3986 respectively are considered safe.
+ Placeholders in the query portion are percent-encoded where the `query` set from
+ RFC 3986 §3.3 is considered safe except for = and & characters.
+
+ Raises:
+ KeyError: If a placeholder is not found in `kwargs`.
+ ValueError: If resulting path contains /./ or /../ segments (including percent-encoded dot-segments).
+ """
+ # Split the template into path, query, and fragment portions.
+ fragment_template: str | None = None
+ query_template: str | None = None
+
+ rest = template
+ if "#" in rest:
+ rest, fragment_template = rest.split("#", 1)
+ if "?" in rest:
+ rest, query_template = rest.split("?", 1)
+ path_template = rest
+
+ # Interpolate each portion with the appropriate quoting rules.
+ path_result = _interpolate(path_template, kwargs, _quote_path_segment_part)
+
+ # Reject dot-segments (. and ..) in the final assembled path. The check
+ # runs after interpolation so that adjacent placeholders or a mix of static
+ # text and placeholders that together form a dot-segment are caught.
+ # Also reject percent-encoded dot-segments to protect against incorrectly
+ # implemented normalization in servers/proxies.
+ for segment in path_result.split("/"):
+ if _DOT_SEGMENT_RE.match(segment):
+ raise ValueError(f"Constructed path {path_result!r} contains dot-segment {segment!r} which is not allowed")
+
+ result = path_result
+ if query_template is not None:
+ result += "?" + _interpolate(query_template, kwargs, _quote_query_part)
+ if fragment_template is not None:
+ result += "#" + _interpolate(fragment_template, kwargs, _quote_fragment_part)
+
+ return result
diff --git a/src/mixedbread/_version.py b/src/mixedbread/_version.py
index 40dca853..84dd5576 100644
--- a/src/mixedbread/_version.py
+++ b/src/mixedbread/_version.py
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
__title__ = "mixedbread"
-__version__ = "0.49.0" # x-release-please-version
+__version__ = "0.50.0" # x-release-please-version
diff --git a/src/mixedbread/resources/api_keys.py b/src/mixedbread/resources/api_keys.py
index 66408456..fb309200 100644
--- a/src/mixedbread/resources/api_keys.py
+++ b/src/mixedbread/resources/api_keys.py
@@ -9,7 +9,7 @@
from ..types import api_key_list_params, api_key_create_params
from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
-from .._utils import maybe_transform, async_maybe_transform
+from .._utils import path_template, maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import (
@@ -131,7 +131,7 @@ def retrieve(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return self._get(
- f"/v1/api-keys/{api_key_id}",
+ path_template("/v1/api-keys/{api_key_id}", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -222,7 +222,7 @@ def delete(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return self._delete(
- f"/v1/api-keys/{api_key_id}",
+ path_template("/v1/api-keys/{api_key_id}", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -264,7 +264,7 @@ def reroll(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return self._post(
- f"/v1/api-keys/{api_key_id}/reroll",
+ path_template("/v1/api-keys/{api_key_id}/reroll", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -303,7 +303,7 @@ def revoke(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return self._post(
- f"/v1/api-keys/{api_key_id}/revoke",
+ path_template("/v1/api-keys/{api_key_id}/revoke", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -415,7 +415,7 @@ async def retrieve(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return await self._get(
- f"/v1/api-keys/{api_key_id}",
+ path_template("/v1/api-keys/{api_key_id}", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -506,7 +506,7 @@ async def delete(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return await self._delete(
- f"/v1/api-keys/{api_key_id}",
+ path_template("/v1/api-keys/{api_key_id}", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -548,7 +548,7 @@ async def reroll(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return await self._post(
- f"/v1/api-keys/{api_key_id}/reroll",
+ path_template("/v1/api-keys/{api_key_id}/reroll", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -587,7 +587,7 @@ async def revoke(
if not api_key_id:
raise ValueError(f"Expected a non-empty value for `api_key_id` but received {api_key_id!r}")
return await self._post(
- f"/v1/api-keys/{api_key_id}/revoke",
+ path_template("/v1/api-keys/{api_key_id}/revoke", api_key_id=api_key_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
diff --git a/src/mixedbread/resources/data_sources/connectors.py b/src/mixedbread/resources/data_sources/connectors.py
index bd913e76..af800c0c 100644
--- a/src/mixedbread/resources/data_sources/connectors.py
+++ b/src/mixedbread/resources/data_sources/connectors.py
@@ -7,7 +7,7 @@
import httpx
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
-from ..._utils import maybe_transform, async_maybe_transform
+from ..._utils import path_template, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
@@ -98,7 +98,7 @@ def create(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return self._post(
- f"/v1/data_sources/{data_source_id}/connectors",
+ path_template("/v1/data_sources/{data_source_id}/connectors", data_source_id=data_source_id),
body=maybe_transform(
{
"store_id": store_id,
@@ -153,7 +153,11 @@ def retrieve(
if not connector_id:
raise ValueError(f"Expected a non-empty value for `connector_id` but received {connector_id!r}")
return self._get(
- f"/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ path_template(
+ "/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ data_source_id=data_source_id,
+ connector_id=connector_id,
+ ),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -216,7 +220,11 @@ def update(
if not connector_id:
raise ValueError(f"Expected a non-empty value for `connector_id` but received {connector_id!r}")
return self._put(
- f"/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ path_template(
+ "/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ data_source_id=data_source_id,
+ connector_id=connector_id,
+ ),
body=maybe_transform(
{
"name": name,
@@ -279,7 +287,7 @@ def list(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return self._get_api_list(
- f"/v1/data_sources/{data_source_id}/connectors",
+ path_template("/v1/data_sources/{data_source_id}/connectors", data_source_id=data_source_id),
page=SyncCursor[DataSourceConnector],
options=make_request_options(
extra_headers=extra_headers,
@@ -337,7 +345,11 @@ def delete(
if not connector_id:
raise ValueError(f"Expected a non-empty value for `connector_id` but received {connector_id!r}")
return self._delete(
- f"/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ path_template(
+ "/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ data_source_id=data_source_id,
+ connector_id=connector_id,
+ ),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -418,7 +430,7 @@ async def create(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return await self._post(
- f"/v1/data_sources/{data_source_id}/connectors",
+ path_template("/v1/data_sources/{data_source_id}/connectors", data_source_id=data_source_id),
body=await async_maybe_transform(
{
"store_id": store_id,
@@ -473,7 +485,11 @@ async def retrieve(
if not connector_id:
raise ValueError(f"Expected a non-empty value for `connector_id` but received {connector_id!r}")
return await self._get(
- f"/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ path_template(
+ "/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ data_source_id=data_source_id,
+ connector_id=connector_id,
+ ),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -536,7 +552,11 @@ async def update(
if not connector_id:
raise ValueError(f"Expected a non-empty value for `connector_id` but received {connector_id!r}")
return await self._put(
- f"/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ path_template(
+ "/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ data_source_id=data_source_id,
+ connector_id=connector_id,
+ ),
body=await async_maybe_transform(
{
"name": name,
@@ -599,7 +619,7 @@ def list(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return self._get_api_list(
- f"/v1/data_sources/{data_source_id}/connectors",
+ path_template("/v1/data_sources/{data_source_id}/connectors", data_source_id=data_source_id),
page=AsyncCursor[DataSourceConnector],
options=make_request_options(
extra_headers=extra_headers,
@@ -657,7 +677,11 @@ async def delete(
if not connector_id:
raise ValueError(f"Expected a non-empty value for `connector_id` but received {connector_id!r}")
return await self._delete(
- f"/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ path_template(
+ "/v1/data_sources/{data_source_id}/connectors/{connector_id}",
+ data_source_id=data_source_id,
+ connector_id=connector_id,
+ ),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
diff --git a/src/mixedbread/resources/data_sources/data_sources.py b/src/mixedbread/resources/data_sources/data_sources.py
index 185eaedb..bb0a9446 100644
--- a/src/mixedbread/resources/data_sources/data_sources.py
+++ b/src/mixedbread/resources/data_sources/data_sources.py
@@ -9,7 +9,7 @@
from ...types import Oauth2Params, data_source_list_params, data_source_create_params, data_source_update_params
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
-from ..._utils import required_args, maybe_transform, async_maybe_transform
+from ..._utils import path_template, required_args, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from .connectors import (
ConnectorsResource,
@@ -208,7 +208,7 @@ def retrieve(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return self._get(
- f"/v1/data_sources/{data_source_id}",
+ path_template("/v1/data_sources/{data_source_id}", data_source_id=data_source_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -329,7 +329,7 @@ def update(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return self._put(
- f"/v1/data_sources/{data_source_id}",
+ path_template("/v1/data_sources/{data_source_id}", data_source_id=data_source_id),
body=maybe_transform(
{
"type": type,
@@ -434,7 +434,7 @@ def delete(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return self._delete(
- f"/v1/data_sources/{data_source_id}",
+ path_template("/v1/data_sources/{data_source_id}", data_source_id=data_source_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -615,7 +615,7 @@ async def retrieve(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return await self._get(
- f"/v1/data_sources/{data_source_id}",
+ path_template("/v1/data_sources/{data_source_id}", data_source_id=data_source_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -736,7 +736,7 @@ async def update(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return await self._put(
- f"/v1/data_sources/{data_source_id}",
+ path_template("/v1/data_sources/{data_source_id}", data_source_id=data_source_id),
body=await async_maybe_transform(
{
"type": type,
@@ -841,7 +841,7 @@ async def delete(
if not data_source_id:
raise ValueError(f"Expected a non-empty value for `data_source_id` but received {data_source_id!r}")
return await self._delete(
- f"/v1/data_sources/{data_source_id}",
+ path_template("/v1/data_sources/{data_source_id}", data_source_id=data_source_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
diff --git a/src/mixedbread/resources/extractions/jobs.py b/src/mixedbread/resources/extractions/jobs.py
index ae48bbf3..3b8a2cf4 100644
--- a/src/mixedbread/resources/extractions/jobs.py
+++ b/src/mixedbread/resources/extractions/jobs.py
@@ -7,7 +7,7 @@
import httpx
from ..._types import Body, Query, Headers, NotGiven, not_given
-from ..._utils import maybe_transform, async_maybe_transform
+from ..._utils import path_template, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
@@ -122,7 +122,7 @@ def retrieve(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return self._get(
- f"/v1/extractions/jobs/{job_id}",
+ path_template("/v1/extractions/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -229,7 +229,7 @@ async def retrieve(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return await self._get(
- f"/v1/extractions/jobs/{job_id}",
+ path_template("/v1/extractions/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
diff --git a/src/mixedbread/resources/files/files.py b/src/mixedbread/resources/files/files.py
index 8536ba20..d09be8bd 100644
--- a/src/mixedbread/resources/files/files.py
+++ b/src/mixedbread/resources/files/files.py
@@ -16,7 +16,7 @@
AsyncUploadsResourceWithStreamingResponse,
)
from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
-from ..._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
+from ..._utils import extract_files, path_template, maybe_transform, deepcopy_minimal, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
@@ -180,7 +180,7 @@ def retrieve(
if not file_id:
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
return self._get(
- f"/v1/files/{file_id}",
+ path_template("/v1/files/{file_id}", file_id=file_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -228,7 +228,7 @@ def update(
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
- f"/v1/files/{file_id}",
+ path_template("/v1/files/{file_id}", file_id=file_id),
body=maybe_transform(body, file_update_params.FileUpdateParams),
files=files,
options=make_request_options(
@@ -334,7 +334,7 @@ def delete(
if not file_id:
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
return self._delete(
- f"/v1/files/{file_id}",
+ path_template("/v1/files/{file_id}", file_id=file_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -374,7 +374,7 @@ def content(
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
return self._get(
- f"/v1/files/{file_id}/content",
+ path_template("/v1/files/{file_id}/content", file_id=file_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -515,7 +515,7 @@ async def retrieve(
if not file_id:
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
return await self._get(
- f"/v1/files/{file_id}",
+ path_template("/v1/files/{file_id}", file_id=file_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -563,7 +563,7 @@ async def update(
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
- f"/v1/files/{file_id}",
+ path_template("/v1/files/{file_id}", file_id=file_id),
body=await async_maybe_transform(body, file_update_params.FileUpdateParams),
files=files,
options=make_request_options(
@@ -669,7 +669,7 @@ async def delete(
if not file_id:
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
return await self._delete(
- f"/v1/files/{file_id}",
+ path_template("/v1/files/{file_id}", file_id=file_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -709,7 +709,7 @@ async def content(
raise ValueError(f"Expected a non-empty value for `file_id` but received {file_id!r}")
extra_headers = {"Accept": "application/octet-stream", **(extra_headers or {})}
return await self._get(
- f"/v1/files/{file_id}/content",
+ path_template("/v1/files/{file_id}/content", file_id=file_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
diff --git a/src/mixedbread/resources/files/uploads.py b/src/mixedbread/resources/files/uploads.py
index dc410621..009fbd06 100644
--- a/src/mixedbread/resources/files/uploads.py
+++ b/src/mixedbread/resources/files/uploads.py
@@ -7,7 +7,7 @@
import httpx
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
-from ..._utils import maybe_transform, async_maybe_transform
+from ..._utils import path_template, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
@@ -129,7 +129,7 @@ def retrieve(
if not upload_id:
raise ValueError(f"Expected a non-empty value for `upload_id` but received {upload_id!r}")
return self._get(
- f"/v1/files/uploads/{upload_id}",
+ path_template("/v1/files/uploads/{upload_id}", upload_id=upload_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -183,7 +183,7 @@ def abort(
if not upload_id:
raise ValueError(f"Expected a non-empty value for `upload_id` but received {upload_id!r}")
return self._post(
- f"/v1/files/uploads/{upload_id}/abort",
+ path_template("/v1/files/uploads/{upload_id}/abort", upload_id=upload_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -223,7 +223,7 @@ def complete(
if not upload_id:
raise ValueError(f"Expected a non-empty value for `upload_id` but received {upload_id!r}")
return self._post(
- f"/v1/files/uploads/{upload_id}/complete",
+ path_template("/v1/files/uploads/{upload_id}/complete", upload_id=upload_id),
body=maybe_transform({"parts": parts}, upload_complete_params.UploadCompleteParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
@@ -333,7 +333,7 @@ async def retrieve(
if not upload_id:
raise ValueError(f"Expected a non-empty value for `upload_id` but received {upload_id!r}")
return await self._get(
- f"/v1/files/uploads/{upload_id}",
+ path_template("/v1/files/uploads/{upload_id}", upload_id=upload_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -387,7 +387,7 @@ async def abort(
if not upload_id:
raise ValueError(f"Expected a non-empty value for `upload_id` but received {upload_id!r}")
return await self._post(
- f"/v1/files/uploads/{upload_id}/abort",
+ path_template("/v1/files/uploads/{upload_id}/abort", upload_id=upload_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -427,7 +427,7 @@ async def complete(
if not upload_id:
raise ValueError(f"Expected a non-empty value for `upload_id` but received {upload_id!r}")
return await self._post(
- f"/v1/files/uploads/{upload_id}/complete",
+ path_template("/v1/files/uploads/{upload_id}/complete", upload_id=upload_id),
body=await async_maybe_transform({"parts": parts}, upload_complete_params.UploadCompleteParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
diff --git a/src/mixedbread/resources/parsing/jobs.py b/src/mixedbread/resources/parsing/jobs.py
index b797da1e..25d83ca8 100644
--- a/src/mixedbread/resources/parsing/jobs.py
+++ b/src/mixedbread/resources/parsing/jobs.py
@@ -11,7 +11,7 @@
from ...lib import polling
from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
from ...lib.multipart_upload import MultipartUploadOptions
-from ..._utils import maybe_transform, async_maybe_transform
+from ..._utils import path_template, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
@@ -145,7 +145,7 @@ def retrieve(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return self._get(
- f"/v1/parsing/jobs/{job_id}",
+ path_template("/v1/parsing/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -254,7 +254,7 @@ def delete(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return self._delete(
- f"/v1/parsing/jobs/{job_id}",
+ path_template("/v1/parsing/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -293,7 +293,7 @@ def cancel(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return self._patch(
- f"/v1/parsing/jobs/{job_id}",
+ path_template("/v1/parsing/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -571,7 +571,7 @@ async def retrieve(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return await self._get(
- f"/v1/parsing/jobs/{job_id}",
+ path_template("/v1/parsing/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -680,7 +680,7 @@ async def delete(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return await self._delete(
- f"/v1/parsing/jobs/{job_id}",
+ path_template("/v1/parsing/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -719,7 +719,7 @@ async def cancel(
if not job_id:
raise ValueError(f"Expected a non-empty value for `job_id` but received {job_id!r}")
return await self._patch(
- f"/v1/parsing/jobs/{job_id}",
+ path_template("/v1/parsing/jobs/{job_id}", job_id=job_id),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
diff --git a/src/mixedbread/resources/stores/files.py b/src/mixedbread/resources/stores/files.py
index 5124082c..5b9052ab 100644
--- a/src/mixedbread/resources/stores/files.py
+++ b/src/mixedbread/resources/stores/files.py
@@ -8,9 +8,9 @@
import httpx
from ...lib import polling
-from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, SequenceNotStr, omit, not_given
+from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
from ...lib.multipart_upload import MultipartUploadOptions
-from ..._utils import maybe_transform, async_maybe_transform
+from ..._utils import path_template, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
@@ -20,18 +20,11 @@
async_to_streamed_response_wrapper,
)
from ..._base_client import make_request_options
-from ...types.stores import (
- file_list_params,
- file_create_params,
- file_search_params,
- file_update_params,
- file_retrieve_params,
-)
+from ...types.stores import file_list_params, file_create_params, file_update_params, file_retrieve_params
from ...types.stores.store_file import StoreFile
from ...types.stores.store_file_status import StoreFileStatus
from ...types.stores.file_list_response import FileListResponse
from ...types.stores.file_delete_response import FileDeleteResponse
-from ...types.stores.file_search_response import FileSearchResponse
__all__ = ["FilesResource", "AsyncFilesResource"]
@@ -108,7 +101,7 @@ def create(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return self._post(
- f"/v1/stores/{store_identifier}/files",
+ path_template("/v1/stores/{store_identifier}/files", store_identifier=store_identifier),
body=maybe_transform(
{
"metadata": metadata,
@@ -169,7 +162,11 @@ def retrieve(
if not file_identifier:
raise ValueError(f"Expected a non-empty value for `file_identifier` but received {file_identifier!r}")
return self._get(
- f"/v1/stores/{store_identifier}/files/{file_identifier}",
+ path_template(
+ "/v1/stores/{store_identifier}/files/{file_identifier}",
+ store_identifier=store_identifier,
+ file_identifier=file_identifier,
+ ),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
@@ -221,7 +218,11 @@ def update(
if not file_identifier:
raise ValueError(f"Expected a non-empty value for `file_identifier` but received {file_identifier!r}")
return self._patch(
- f"/v1/stores/{store_identifier}/files/{file_identifier}",
+ path_template(
+ "/v1/stores/{store_identifier}/files/{file_identifier}",
+ store_identifier=store_identifier,
+ file_identifier=file_identifier,
+ ),
body=maybe_transform({"metadata": metadata}, file_update_params.FileUpdateParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
@@ -285,7 +286,7 @@ def list(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return self._post(
- f"/v1/stores/{store_identifier}/files/list",
+ path_template("/v1/stores/{store_identifier}/files/list", store_identifier=store_identifier),
body=maybe_transform(
{
"limit": limit,
@@ -343,76 +344,15 @@ def delete(
if not file_identifier:
raise ValueError(f"Expected a non-empty value for `file_identifier` but received {file_identifier!r}")
return self._delete(
- f"/v1/stores/{store_identifier}/files/{file_identifier}",
- options=make_request_options(
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
- ),
- cast_to=FileDeleteResponse,
- )
-
- def search(
- self,
- *,
- query: file_search_params.Query,
- store_identifiers: SequenceNotStr[str],
- top_k: int | Omit = omit,
- filters: Optional[file_search_params.Filters] | Omit = omit,
- file_ids: Union[Iterable[object], SequenceNotStr[str], None] | Omit = omit,
- search_options: file_search_params.SearchOptions | Omit = omit,
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
- # The extra values given here take precedence over values defined on the client or passed to this method.
- extra_headers: Headers | None = None,
- extra_query: Query | None = None,
- extra_body: Body | None = None,
- timeout: float | httpx.Timeout | None | NotGiven = not_given,
- ) -> FileSearchResponse:
- """
- Search for files within a store based on semantic similarity.
-
- Args: store_identifier: The ID or name of the store to search within
- search_params: Search configuration including query text, pagination, and
- filters
-
- Returns: StoreFileSearchResponse: List of matching files with relevance scores
-
- Args:
- query: Search query text
-
- store_identifiers: IDs or names of stores to search
-
- top_k: Number of results to return
-
- filters: Optional filter conditions
-
- file_ids: Optional list of file IDs to filter chunks by (inclusion filter)
-
- search_options: Search configuration options
-
- extra_headers: Send extra headers
-
- extra_query: Add additional query parameters to the request
-
- extra_body: Add additional JSON properties to the request
-
- timeout: Override the client-level default timeout for this request, in seconds
- """
- return self._post(
- "/v1/stores/files/search",
- body=maybe_transform(
- {
- "query": query,
- "store_identifiers": store_identifiers,
- "top_k": top_k,
- "filters": filters,
- "file_ids": file_ids,
- "search_options": search_options,
- },
- file_search_params.FileSearchParams,
+ path_template(
+ "/v1/stores/{store_identifier}/files/{file_identifier}",
+ store_identifier=store_identifier,
+ file_identifier=file_identifier,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
- cast_to=FileSearchResponse,
+ cast_to=FileDeleteResponse,
)
def poll(
@@ -657,7 +597,7 @@ async def create(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return await self._post(
- f"/v1/stores/{store_identifier}/files",
+ path_template("/v1/stores/{store_identifier}/files", store_identifier=store_identifier),
body=await async_maybe_transform(
{
"metadata": metadata,
@@ -718,7 +658,11 @@ async def retrieve(
if not file_identifier:
raise ValueError(f"Expected a non-empty value for `file_identifier` but received {file_identifier!r}")
return await self._get(
- f"/v1/stores/{store_identifier}/files/{file_identifier}",
+ path_template(
+ "/v1/stores/{store_identifier}/files/{file_identifier}",
+ store_identifier=store_identifier,
+ file_identifier=file_identifier,
+ ),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
@@ -772,7 +716,11 @@ async def update(
if not file_identifier:
raise ValueError(f"Expected a non-empty value for `file_identifier` but received {file_identifier!r}")
return await self._patch(
- f"/v1/stores/{store_identifier}/files/{file_identifier}",
+ path_template(
+ "/v1/stores/{store_identifier}/files/{file_identifier}",
+ store_identifier=store_identifier,
+ file_identifier=file_identifier,
+ ),
body=await async_maybe_transform({"metadata": metadata}, file_update_params.FileUpdateParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
@@ -836,7 +784,7 @@ async def list(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return await self._post(
- f"/v1/stores/{store_identifier}/files/list",
+ path_template("/v1/stores/{store_identifier}/files/list", store_identifier=store_identifier),
body=await async_maybe_transform(
{
"limit": limit,
@@ -894,76 +842,15 @@ async def delete(
if not file_identifier:
raise ValueError(f"Expected a non-empty value for `file_identifier` but received {file_identifier!r}")
return await self._delete(
- f"/v1/stores/{store_identifier}/files/{file_identifier}",
- options=make_request_options(
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
- ),
- cast_to=FileDeleteResponse,
- )
-
- async def search(
- self,
- *,
- query: file_search_params.Query,
- store_identifiers: SequenceNotStr[str],
- top_k: int | Omit = omit,
- filters: Optional[file_search_params.Filters] | Omit = omit,
- file_ids: Union[Iterable[object], SequenceNotStr[str], None] | Omit = omit,
- search_options: file_search_params.SearchOptions | Omit = omit,
- # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
- # The extra values given here take precedence over values defined on the client or passed to this method.
- extra_headers: Headers | None = None,
- extra_query: Query | None = None,
- extra_body: Body | None = None,
- timeout: float | httpx.Timeout | None | NotGiven = not_given,
- ) -> FileSearchResponse:
- """
- Search for files within a store based on semantic similarity.
-
- Args: store_identifier: The ID or name of the store to search within
- search_params: Search configuration including query text, pagination, and
- filters
-
- Returns: StoreFileSearchResponse: List of matching files with relevance scores
-
- Args:
- query: Search query text
-
- store_identifiers: IDs or names of stores to search
-
- top_k: Number of results to return
-
- filters: Optional filter conditions
-
- file_ids: Optional list of file IDs to filter chunks by (inclusion filter)
-
- search_options: Search configuration options
-
- extra_headers: Send extra headers
-
- extra_query: Add additional query parameters to the request
-
- extra_body: Add additional JSON properties to the request
-
- timeout: Override the client-level default timeout for this request, in seconds
- """
- return await self._post(
- "/v1/stores/files/search",
- body=await async_maybe_transform(
- {
- "query": query,
- "store_identifiers": store_identifiers,
- "top_k": top_k,
- "filters": filters,
- "file_ids": file_ids,
- "search_options": search_options,
- },
- file_search_params.FileSearchParams,
+ path_template(
+ "/v1/stores/{store_identifier}/files/{file_identifier}",
+ store_identifier=store_identifier,
+ file_identifier=file_identifier,
),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
- cast_to=FileSearchResponse,
+ cast_to=FileDeleteResponse,
)
async def poll(
@@ -1155,9 +1042,6 @@ def __init__(self, files: FilesResource) -> None:
self.delete = to_raw_response_wrapper(
files.delete,
)
- self.search = to_raw_response_wrapper(
- files.search,
- )
class AsyncFilesResourceWithRawResponse:
@@ -1179,9 +1063,6 @@ def __init__(self, files: AsyncFilesResource) -> None:
self.delete = async_to_raw_response_wrapper(
files.delete,
)
- self.search = async_to_raw_response_wrapper(
- files.search,
- )
class FilesResourceWithStreamingResponse:
@@ -1203,9 +1084,6 @@ def __init__(self, files: FilesResource) -> None:
self.delete = to_streamed_response_wrapper(
files.delete,
)
- self.search = to_streamed_response_wrapper(
- files.search,
- )
class AsyncFilesResourceWithStreamingResponse:
@@ -1227,6 +1105,3 @@ def __init__(self, files: AsyncFilesResource) -> None:
self.delete = async_to_streamed_response_wrapper(
files.delete,
)
- self.search = async_to_streamed_response_wrapper(
- files.search,
- )
diff --git a/src/mixedbread/resources/stores/stores.py b/src/mixedbread/resources/stores/stores.py
index 1834f5a8..c3700b0b 100644
--- a/src/mixedbread/resources/stores/stores.py
+++ b/src/mixedbread/resources/stores/stores.py
@@ -23,7 +23,7 @@
store_question_answering_params,
)
from ..._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
-from ..._utils import maybe_transform, async_maybe_transform
+from ..._utils import path_template, maybe_transform, async_maybe_transform
from ..._compat import cached_property
from ..._resource import SyncAPIResource, AsyncAPIResource
from ..._response import (
@@ -170,7 +170,7 @@ def retrieve(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return self._get(
- f"/v1/stores/{store_identifier}",
+ path_template("/v1/stores/{store_identifier}", store_identifier=store_identifier),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -226,7 +226,7 @@ def update(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return self._put(
- f"/v1/stores/{store_identifier}",
+ path_template("/v1/stores/{store_identifier}", store_identifier=store_identifier),
body=maybe_transform(
{
"name": name,
@@ -342,7 +342,7 @@ def delete(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return self._delete(
- f"/v1/stores/{store_identifier}",
+ path_template("/v1/stores/{store_identifier}", store_identifier=store_identifier),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -691,7 +691,7 @@ async def retrieve(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return await self._get(
- f"/v1/stores/{store_identifier}",
+ path_template("/v1/stores/{store_identifier}", store_identifier=store_identifier),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
@@ -747,7 +747,7 @@ async def update(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return await self._put(
- f"/v1/stores/{store_identifier}",
+ path_template("/v1/stores/{store_identifier}", store_identifier=store_identifier),
body=await async_maybe_transform(
{
"name": name,
@@ -863,7 +863,7 @@ async def delete(
if not store_identifier:
raise ValueError(f"Expected a non-empty value for `store_identifier` but received {store_identifier!r}")
return await self._delete(
- f"/v1/stores/{store_identifier}",
+ path_template("/v1/stores/{store_identifier}", store_identifier=store_identifier),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
diff --git a/src/mixedbread/types/scored_audio_url_input_chunk.py b/src/mixedbread/types/scored_audio_url_input_chunk.py
index c82677c8..b81f41f5 100644
--- a/src/mixedbread/types/scored_audio_url_input_chunk.py
+++ b/src/mixedbread/types/scored_audio_url_input_chunk.py
@@ -309,9 +309,6 @@ class ScoredAudioURLInputChunk(BaseModel):
transcription: Optional[str] = None
"""speech recognition (sr) text of the audio"""
- summary: Optional[str] = None
- """summary of the audio"""
-
audio_url: Optional[AudioURL] = None
"""Model for audio URL validation."""
diff --git a/src/mixedbread/types/scored_video_url_input_chunk.py b/src/mixedbread/types/scored_video_url_input_chunk.py
index 7be647ff..4e493982 100644
--- a/src/mixedbread/types/scored_video_url_input_chunk.py
+++ b/src/mixedbread/types/scored_video_url_input_chunk.py
@@ -309,8 +309,5 @@ class ScoredVideoURLInputChunk(BaseModel):
transcription: Optional[str] = None
"""speech recognition (sr) text of the video"""
- summary: Optional[str] = None
- """summary of the video"""
-
video_url: Optional[VideoURL] = None
"""Model for video URL validation."""
diff --git a/src/mixedbread/types/stores/__init__.py b/src/mixedbread/types/stores/__init__.py
index 50862586..0d8d6b2e 100644
--- a/src/mixedbread/types/stores/__init__.py
+++ b/src/mixedbread/types/stores/__init__.py
@@ -4,12 +4,9 @@
from .store_file import StoreFile as StoreFile
from .file_list_params import FileListParams as FileListParams
-from .scored_store_file import ScoredStoreFile as ScoredStoreFile
from .store_file_status import StoreFileStatus as StoreFileStatus
from .file_create_params import FileCreateParams as FileCreateParams
from .file_list_response import FileListResponse as FileListResponse
-from .file_search_params import FileSearchParams as FileSearchParams
from .file_update_params import FileUpdateParams as FileUpdateParams
from .file_delete_response import FileDeleteResponse as FileDeleteResponse
from .file_retrieve_params import FileRetrieveParams as FileRetrieveParams
-from .file_search_response import FileSearchResponse as FileSearchResponse
diff --git a/src/mixedbread/types/stores/file_search_params.py b/src/mixedbread/types/stores/file_search_params.py
deleted file mode 100644
index c1b5dee9..00000000
--- a/src/mixedbread/types/stores/file_search_params.py
+++ /dev/null
@@ -1,128 +0,0 @@
-# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-from __future__ import annotations
-
-from typing import Union, Iterable, Optional
-from typing_extensions import Required, TypeAlias, TypedDict
-
-from ..._types import SequenceNotStr
-from ..extractions.text_input_param import TextInputParam
-from ..extractions.image_url_input_param import ImageURLInputParam
-from ..shared_params.search_filter_condition import SearchFilterCondition
-
-__all__ = [
- "FileSearchParams",
- "Query",
- "Filters",
- "FiltersUnionMember2",
- "SearchOptions",
- "SearchOptionsRerank",
- "SearchOptionsRerankRerankConfig",
- "SearchOptionsAgentic",
- "SearchOptionsAgenticAgenticSearchConfig",
-]
-
-
-class FileSearchParams(TypedDict, total=False):
- query: Required[Query]
- """Search query text"""
-
- store_identifiers: Required[SequenceNotStr[str]]
- """IDs or names of stores to search"""
-
- top_k: int
- """Number of results to return"""
-
- filters: Optional[Filters]
- """Optional filter conditions"""
-
- file_ids: Union[Iterable[object], SequenceNotStr[str], None]
- """Optional list of file IDs to filter chunks by (inclusion filter)"""
-
- search_options: SearchOptions
- """Search configuration options"""
-
-
-Query: TypeAlias = Union[str, ImageURLInputParam, TextInputParam]
-
-FiltersUnionMember2: TypeAlias = Union["SearchFilter", SearchFilterCondition]
-
-Filters: TypeAlias = Union["SearchFilter", SearchFilterCondition, Iterable[FiltersUnionMember2]]
-
-
-class SearchOptionsRerankRerankConfig(TypedDict, total=False):
- """Represents a reranking configuration."""
-
- model: str
- """The name of the reranking model"""
-
- with_metadata: Union[bool, SequenceNotStr[str]]
- """Whether to include metadata in the reranked results"""
-
- top_k: Optional[int]
- """Maximum number of results to return after reranking.
-
- If None, returns all reranked results.
- """
-
-
-SearchOptionsRerank: TypeAlias = Union[bool, SearchOptionsRerankRerankConfig]
-
-
-class SearchOptionsAgenticAgenticSearchConfig(TypedDict, total=False):
- """Configuration for agentic multi-query search."""
-
- max_rounds: int
- """Maximum number of search rounds"""
-
- queries_per_round: int
- """Maximum queries per round"""
-
- instructions: Optional[str]
- """
- Additional custom instructions (followed only when not in conflict with existing
- rules)
- """
-
-
-SearchOptionsAgentic: TypeAlias = Union[bool, SearchOptionsAgenticAgenticSearchConfig]
-
-
-class SearchOptions(TypedDict, total=False):
- """Search configuration options"""
-
- score_threshold: float
- """Minimum similarity score threshold"""
-
- rewrite_query: bool
- """Whether to rewrite the query.
-
- Ignored when agentic is enabled (the agent handles query decomposition).
- """
-
- rerank: Optional[SearchOptionsRerank]
- """Whether to rerank results and optional reranking configuration.
-
- Ignored when agentic is enabled (the agent handles ranking).
- """
-
- agentic: Optional[SearchOptionsAgentic]
- """
- Whether to use agentic multi-query search with automatic query decomposition and
- ranking. When enabled, rewrite_query and rerank options are ignored.
- """
-
- return_metadata: bool
- """Whether to return file metadata"""
-
- return_chunks: bool
- """Whether to return matching text chunks"""
-
- chunks_per_file: int
- """Number of chunks to return for each file"""
-
- apply_search_rules: bool
- """Whether to apply search rules"""
-
-
-from ..shared_params.search_filter import SearchFilter
diff --git a/src/mixedbread/types/stores/file_search_response.py b/src/mixedbread/types/stores/file_search_response.py
deleted file mode 100644
index 304512e4..00000000
--- a/src/mixedbread/types/stores/file_search_response.py
+++ /dev/null
@@ -1,17 +0,0 @@
-# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-from typing import List, Optional
-from typing_extensions import Literal
-
-from ..._models import BaseModel
-from .scored_store_file import ScoredStoreFile
-
-__all__ = ["FileSearchResponse"]
-
-
-class FileSearchResponse(BaseModel):
- object: Optional[Literal["list"]] = None
- """The object type of the response"""
-
- data: List[ScoredStoreFile]
- """The list of scored store files"""
diff --git a/src/mixedbread/types/stores/scored_store_file.py b/src/mixedbread/types/stores/scored_store_file.py
deleted file mode 100644
index 87483138..00000000
--- a/src/mixedbread/types/stores/scored_store_file.py
+++ /dev/null
@@ -1,77 +0,0 @@
-# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-from typing import List, Union, Optional
-from datetime import datetime
-from typing_extensions import Literal, Annotated, TypeAlias
-
-from ..._utils import PropertyInfo
-from ..._models import BaseModel
-from .store_file_status import StoreFileStatus
-from ..scored_text_input_chunk import ScoredTextInputChunk
-from ..scored_audio_url_input_chunk import ScoredAudioURLInputChunk
-from ..scored_image_url_input_chunk import ScoredImageURLInputChunk
-from ..scored_video_url_input_chunk import ScoredVideoURLInputChunk
-
-__all__ = ["ScoredStoreFile", "Config", "Chunk"]
-
-
-class Config(BaseModel):
- """Configuration for a file."""
-
- parsing_strategy: Optional[Literal["fast", "high_quality"]] = None
- """Strategy for adding the file, this overrides the store-level default"""
-
-
-Chunk: TypeAlias = Annotated[
- Union[ScoredTextInputChunk, ScoredImageURLInputChunk, ScoredAudioURLInputChunk, ScoredVideoURLInputChunk],
- PropertyInfo(discriminator="type"),
-]
-
-
-class ScoredStoreFile(BaseModel):
- """Represents a scored store file."""
-
- id: str
- """Unique identifier for the file"""
-
- filename: Optional[str] = None
- """Name of the file"""
-
- metadata: Optional[object] = None
- """Optional file metadata"""
-
- external_id: Optional[str] = None
- """External identifier for this file in the store"""
-
- status: Optional[StoreFileStatus] = None
- """Processing status of the file"""
-
- last_error: Optional[object] = None
- """Last error message if processing failed"""
-
- store_id: str
- """ID of the containing store"""
-
- created_at: datetime
- """Timestamp of store file creation"""
-
- version: Optional[int] = None
- """Version number of the file"""
-
- usage_bytes: Optional[int] = None
- """Storage usage in bytes"""
-
- usage_tokens: Optional[int] = None
- """Storage usage in tokens"""
-
- config: Optional[Config] = None
- """Configuration for a file."""
-
- object: Optional[Literal["store.file"]] = None
- """Type of the object"""
-
- chunks: Optional[List[Chunk]] = None
- """Array of scored file chunks"""
-
- score: float
- """score of the file"""
diff --git a/src/mixedbread/types/stores/store_file.py b/src/mixedbread/types/stores/store_file.py
index eb1baefc..f1f8674c 100644
--- a/src/mixedbread/types/stores/store_file.py
+++ b/src/mixedbread/types/stores/store_file.py
@@ -891,9 +891,6 @@ class ChunkAudioURLInputChunk(BaseModel):
transcription: Optional[str] = None
"""speech recognition (sr) text of the audio"""
- summary: Optional[str] = None
- """summary of the audio"""
-
audio_url: Optional[ChunkAudioURLInputChunkAudioURL] = None
"""Model for audio URL validation."""
@@ -1172,9 +1169,6 @@ class ChunkVideoURLInputChunk(BaseModel):
transcription: Optional[str] = None
"""speech recognition (sr) text of the video"""
- summary: Optional[str] = None
- """summary of the video"""
-
video_url: Optional[ChunkVideoURLInputChunkVideoURL] = None
"""Model for video URL validation."""
@@ -1229,3 +1223,6 @@ class StoreFile(BaseModel):
chunks: Optional[List[Chunk]] = None
"""chunks"""
+
+ content_url: str
+ """Presigned URL for file content"""
diff --git a/tests/api_resources/stores/test_files.py b/tests/api_resources/stores/test_files.py
index f59802bf..7baab6c8 100644
--- a/tests/api_resources/stores/test_files.py
+++ b/tests/api_resources/stores/test_files.py
@@ -13,7 +13,6 @@
StoreFile,
FileListResponse,
FileDeleteResponse,
- FileSearchResponse,
)
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
@@ -295,65 +294,6 @@ def test_path_params_delete(self, client: Mixedbread) -> None:
store_identifier="store_identifier",
)
- @parametrize
- def test_method_search(self, client: Mixedbread) -> None:
- file = client.stores.files.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- )
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- @parametrize
- def test_method_search_with_all_params(self, client: Mixedbread) -> None:
- file = client.stores.files.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- top_k=1,
- filters={
- "all": [{}, {}],
- "any": [{}, {}],
- "none": [{}, {}],
- },
- file_ids=["123e4567-e89b-12d3-a456-426614174000", "123e4567-e89b-12d3-a456-426614174001"],
- search_options={
- "score_threshold": 0,
- "rewrite_query": True,
- "rerank": True,
- "agentic": True,
- "return_metadata": True,
- "return_chunks": True,
- "chunks_per_file": 0,
- "apply_search_rules": True,
- },
- )
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- @parametrize
- def test_raw_response_search(self, client: Mixedbread) -> None:
- response = client.stores.files.with_raw_response.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- )
-
- assert response.is_closed is True
- assert response.http_request.headers.get("X-Stainless-Lang") == "python"
- file = response.parse()
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- @parametrize
- def test_streaming_response_search(self, client: Mixedbread) -> None:
- with client.stores.files.with_streaming_response.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- ) as response:
- assert not response.is_closed
- assert response.http_request.headers.get("X-Stainless-Lang") == "python"
-
- file = response.parse()
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- assert cast(Any, response.is_closed) is True
-
class TestAsyncFiles:
parametrize = pytest.mark.parametrize(
@@ -632,62 +572,3 @@ async def test_path_params_delete(self, async_client: AsyncMixedbread) -> None:
file_identifier="",
store_identifier="store_identifier",
)
-
- @parametrize
- async def test_method_search(self, async_client: AsyncMixedbread) -> None:
- file = await async_client.stores.files.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- )
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- @parametrize
- async def test_method_search_with_all_params(self, async_client: AsyncMixedbread) -> None:
- file = await async_client.stores.files.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- top_k=1,
- filters={
- "all": [{}, {}],
- "any": [{}, {}],
- "none": [{}, {}],
- },
- file_ids=["123e4567-e89b-12d3-a456-426614174000", "123e4567-e89b-12d3-a456-426614174001"],
- search_options={
- "score_threshold": 0,
- "rewrite_query": True,
- "rerank": True,
- "agentic": True,
- "return_metadata": True,
- "return_chunks": True,
- "chunks_per_file": 0,
- "apply_search_rules": True,
- },
- )
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- @parametrize
- async def test_raw_response_search(self, async_client: AsyncMixedbread) -> None:
- response = await async_client.stores.files.with_raw_response.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- )
-
- assert response.is_closed is True
- assert response.http_request.headers.get("X-Stainless-Lang") == "python"
- file = await response.parse()
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- @parametrize
- async def test_streaming_response_search(self, async_client: AsyncMixedbread) -> None:
- async with async_client.stores.files.with_streaming_response.search(
- query="how to configure SSL",
- store_identifiers=["string"],
- ) as response:
- assert not response.is_closed
- assert response.http_request.headers.get("X-Stainless-Lang") == "python"
-
- file = await response.parse()
- assert_matches_type(FileSearchResponse, file, path=["response"])
-
- assert cast(Any, response.is_closed) is True
diff --git a/tests/test_utils/test_path.py b/tests/test_utils/test_path.py
new file mode 100644
index 00000000..7d148421
--- /dev/null
+++ b/tests/test_utils/test_path.py
@@ -0,0 +1,89 @@
+from __future__ import annotations
+
+from typing import Any
+
+import pytest
+
+from mixedbread._utils._path import path_template
+
+
+@pytest.mark.parametrize(
+ "template, kwargs, expected",
+ [
+ ("/v1/{id}", dict(id="abc"), "/v1/abc"),
+ ("/v1/{a}/{b}", dict(a="x", b="y"), "/v1/x/y"),
+ ("/v1/{a}{b}/path/{c}?val={d}#{e}", dict(a="x", b="y", c="z", d="u", e="v"), "/v1/xy/path/z?val=u#v"),
+ ("/{w}/{w}", dict(w="echo"), "/echo/echo"),
+ ("/v1/static", {}, "/v1/static"),
+ ("", {}, ""),
+ ("/v1/?q={n}&count=10", dict(n=42), "/v1/?q=42&count=10"),
+ ("/v1/{v}", dict(v=None), "/v1/null"),
+ ("/v1/{v}", dict(v=True), "/v1/true"),
+ ("/v1/{v}", dict(v=False), "/v1/false"),
+ ("/v1/{v}", dict(v=".hidden"), "/v1/.hidden"), # dot prefix ok
+ ("/v1/{v}", dict(v="file.txt"), "/v1/file.txt"), # dot in middle ok
+ ("/v1/{v}", dict(v="..."), "/v1/..."), # triple dot ok
+ ("/v1/{a}{b}", dict(a=".", b="txt"), "/v1/.txt"), # dot var combining with adjacent to be ok
+ ("/items?q={v}#{f}", dict(v=".", f=".."), "/items?q=.#.."), # dots in query/fragment are fine
+ (
+ "/v1/{a}?query={b}",
+ dict(a="../../other/endpoint", b="a&bad=true"),
+ "/v1/..%2F..%2Fother%2Fendpoint?query=a%26bad%3Dtrue",
+ ),
+ ("/v1/{val}", dict(val="a/b/c"), "/v1/a%2Fb%2Fc"),
+ ("/v1/{val}", dict(val="a/b/c?query=value"), "/v1/a%2Fb%2Fc%3Fquery=value"),
+ ("/v1/{val}", dict(val="a/b/c?query=value&bad=true"), "/v1/a%2Fb%2Fc%3Fquery=value&bad=true"),
+ ("/v1/{val}", dict(val="%20"), "/v1/%2520"), # escapes escape sequences in input
+ # Query: slash and ? are safe, # is not
+ ("/items?q={v}", dict(v="a/b"), "/items?q=a/b"),
+ ("/items?q={v}", dict(v="a?b"), "/items?q=a?b"),
+ ("/items?q={v}", dict(v="a#b"), "/items?q=a%23b"),
+ ("/items?q={v}", dict(v="a b"), "/items?q=a%20b"),
+ # Fragment: slash and ? are safe
+ ("/docs#{v}", dict(v="a/b"), "/docs#a/b"),
+ ("/docs#{v}", dict(v="a?b"), "/docs#a?b"),
+ # Path: slash, ? and # are all encoded
+ ("/v1/{v}", dict(v="a/b"), "/v1/a%2Fb"),
+ ("/v1/{v}", dict(v="a?b"), "/v1/a%3Fb"),
+ ("/v1/{v}", dict(v="a#b"), "/v1/a%23b"),
+ # same var encoded differently by component
+ (
+ "/v1/{v}?q={v}#{v}",
+ dict(v="a/b?c#d"),
+ "/v1/a%2Fb%3Fc%23d?q=a/b?c%23d#a/b?c%23d",
+ ),
+ ("/v1/{val}", dict(val="x?admin=true"), "/v1/x%3Fadmin=true"), # query injection
+ ("/v1/{val}", dict(val="x#admin"), "/v1/x%23admin"), # fragment injection
+ ],
+)
+def test_interpolation(template: str, kwargs: dict[str, Any], expected: str) -> None:
+ assert path_template(template, **kwargs) == expected
+
+
+def test_missing_kwarg_raises_key_error() -> None:
+ with pytest.raises(KeyError, match="org_id"):
+ path_template("/v1/{org_id}")
+
+
+@pytest.mark.parametrize(
+ "template, kwargs",
+ [
+ ("{a}/path", dict(a=".")),
+ ("{a}/path", dict(a="..")),
+ ("/v1/{a}", dict(a=".")),
+ ("/v1/{a}", dict(a="..")),
+ ("/v1/{a}/path", dict(a=".")),
+ ("/v1/{a}/path", dict(a="..")),
+ ("/v1/{a}{b}", dict(a=".", b=".")), # adjacent vars → ".."
+ ("/v1/{a}.", dict(a=".")), # var + static → ".."
+ ("/v1/{a}{b}", dict(a="", b=".")), # empty + dot → "."
+ ("/v1/%2e/{x}", dict(x="ok")), # encoded dot in static text
+ ("/v1/%2e./{x}", dict(x="ok")), # mixed encoded ".." in static
+ ("/v1/.%2E/{x}", dict(x="ok")), # mixed encoded ".." in static
+ ("/v1/{v}?q=1", dict(v="..")),
+ ("/v1/{v}#frag", dict(v="..")),
+ ],
+)
+def test_dot_segment_rejected(template: str, kwargs: dict[str, Any]) -> None:
+ with pytest.raises(ValueError, match="dot-segment"):
+ path_template(template, **kwargs)