Metadata-Version: 2.4
Name: simready-search
Version: 2026.10.0
Summary: SimReady Asset Search Library
Author: NVIDIA Corporation
License-Expression: Apache-2.0
Project-URL: Homepage, https://www.nvidia.com
Keywords: nvidia,simready,search
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: requests>=2.33.0
Requires-Dist: boto3>=1.40.46
Requires-Dist: urllib3<3,>=2.8.0
Dynamic: license-file

# Asset Search Library (`simready.search`)

Python library for searching SimReady assets. It loads a project's asset metadata
cache and finds assets that match the filters you pass.

## Install

```bash
pip install simready.search
```

## Authentication

Service sources use HTTP Basic auth with a Nucleus API token. Set two environment
variables:

| Variable | Value |
| --- | --- |
| `USD_SEARCH_USERNAME` | `$omni-api-token` |
| `USD_SEARCH_PASSWORD` | Your Nucleus API token |

Set both **before** you import the library. The library reads them once, at import
time, so a value you set later has no effect:

```python
import os

os.environ["USD_SEARCH_USERNAME"] = "$omni-api-token"
os.environ["USD_SEARCH_PASSWORD"] = "<your Nucleus API token>"

from simready.search import AssetLibrary  # import after you set the variables
```

Cache, S3, and indexed sources do not use these variables.

## Initialization

Construct an instance of the `AssetLibrary` class, then add one or more search sources:

| Method | Source | Async |
| --- | --- | --- |
| `add_cache_source` | Local `project_config.toml` | Yes |
| `add_s3_source` | S3 `project_config.toml` | Yes |
| `add_indexed_source` | Local or S3 directory without a cache | Yes |
| `add_service_source` | Web-hosted search service | No |

Await the first three. Call `add_service_source` directly.

Indexed sources find file paths only, not metadata. `SearchFilterPathContains` is the
only filter that matches an asset added that way.

```python
import asyncio
from simready.search import (
    AssetLibrary,
    AssetLibraryNetworkError,
    SearchFilterArbitraryDictValue,
    SearchFilterClass,
    SearchFilterCountry,
    SearchFilterFeature,
    SearchFilterHeight,
    SearchFilterLLMQuery,
    SearchFilterPathContains,
    SearchFilterScenePOI,
)


async def main():
    # Option 1: initialize with project_config.toml referring to a workspace_cache.json
    project_config_path = "d:/simready_foundations/sample_content/project_config.toml"
    asset_library = AssetLibrary()
    await asset_library.add_cache_source(project_config_path)

    # Option 2: no project_config, just index some directories
    asset_library = AssetLibrary()
    await asset_library.add_indexed_source("d:/some_content/", "local")
    await asset_library.add_indexed_source("d:/some_more_content/", "local")

    # Option 3: strict network error handling
    asset_library = AssetLibrary(raise_on_network_error=True)

asyncio.run(main())
```

`AssetLibrary` constructor args:

- `log_func` (default `None`): callback for library log messages.
- `raise_on_network_error` (default `False`): when `True`, raises `AssetLibraryNetworkError` for service/S3 failures.

When `raise_on_network_error=False`, network failures are logged and the library returns safe empty/partial results.

## Searching

`AssetLibrary.search(...)` takes seven keyword arguments. The first four are optional
lists of search filters:

- **include_all**: include an asset if it passes **all** of these filters
- **include_any**: include an asset if it passes **any one** of these filters
- **exclude_all**: exclude an asset if it passes **all** of these filters
- **exclude_any**: exclude an asset if it passes **any one** of these filters

The other three control the result set:

- **remove_duplicates** (default `True`): collapse the same asset found in more than one source.
- **base_paths** (default `None`): restrict the search to assets under these path prefixes.
- **max_count** (default `None`): return at most this many assets. Must be a positive
  integer. A value that is not returns no results and logs a warning.

It returns a `SearchResults` sequence of `AssetData` for assets which were included and
not excluded. Iterate, index, and take `len` as you would a list. Per-search facts live on
`matches.search_metadata` -- refer to [Per-search metadata](#per-search-metadata).

## Filters

| Filter | Arguments |
| --- | --- |
| `SearchFilterPathContains` | `substring` |
| `SearchFilterClass` | `class_name` |
| `SearchFilterTag` | `tag` |
| `SearchFilterFeature` | `feature`, `version`, `case_sensitive` |
| `SearchFilterProfile` | `profile`, `version`, `case_sensitive` |
| `SearchFilterScenePOI` | `poi_tag` |
| `SearchFilterCountry` | `country_name` |
| `SearchFilterHeight` | `minimum`, `maximum` |
| `SearchFilterArbitraryDictValue` | `dict_path`, `value` |
| `SearchFilterPhrase` | `phrase` |
| `SearchFilterLLMQuery` | `query` |
| `SearchFilterRelevance` | `minimum` |

`SearchFilterFeature` and `SearchFilterProfile` accept glob patterns and match any
version unless you pass one.

`SearchFilterHeight` measures the asset's Z extent, the up axis of SimReady and Isaac
content. Y-up assets are not handled.

## Result metadata

Metadata comes back at two levels, and the two never mix.

### Per-asset metadata

`AssetData.metadata` is an `AssetMetadata` -- the same type in every search mode -- or `None` when
the source reports nothing about that particular asset. It carries `relevance_score`, a float in
`[0, 1]` derived from the hit's raw search scores. Only service sources populate it today; cache
and indexed results report `None`.

### Per-search metadata

`matches.search_metadata` is a `SearchMetadata`. It describes the search itself, not any
one result: values every result shares, such as how a natural-language query was parsed.
One dataclass covers every search mode. Every field is optional, because the source that
answered decides which ones are set.

Only service sources set anything today. They set `raw_search_query`, the query that was
sent, and `llm_parse_result`, described under
[Natural-language queries](#natural-language-queries).

A cache-only or index-only search still sets `search_metadata` to an empty
`SearchMetadata`. So does a search no source answered. You never have to check for
`None` first.

### Full metadata for one asset

`fetch_asset_metadata` returns the complete `SimReadyMetadata` for a single asset. Pass
`source_id` to choose among several service sources:

```python
metadata = asset_library.fetch_asset_metadata(asset_data.asset_path)
```

Only service sources answer this call.

## Examples

### Example 1: find really tall props which are neither structures nor trees

```python
matches = asset_library.search(
    include_all=[SearchFilterClass("prop"), SearchFilterHeight(minimum=25)],
    exclude_any=[SearchFilterPathContains("structures"), SearchFilterPathContains("vegetation")],
)
for asset_data in matches:
    print(asset_data.asset_path)
```

### Example 2: find red American signs

```python
matches = asset_library.search(
    include_all=[
        SearchFilterArbitraryDictValue(["factory", "sign", "panel_color"], "red"),
        SearchFilterCountry("usa"),
    ]
)
for asset_data in matches:
    print(asset_data.asset_path)
```

### Example 3: find people (or people-height objects), except for Chinese signs

```python
matches = asset_library.search(
    include_any=[SearchFilterClass("character"), SearchFilterHeight(minimum=1.55, maximum=1.95)],
    exclude_all=[SearchFilterCountry("china"), SearchFilterClass("sign")],
)
for asset_data in matches:
    print(asset_data.asset_path)
```

## Querying all values for a filter

### Example 4: query all possible values for Scene Point Of Interest (POI) tags

```python
poi_tags = asset_library.get_all_values(SearchFilterScenePOI)
print(sorted(poi_tags))
```

Six filters support this: `SearchFilterClass`, `SearchFilterTag`, `SearchFilterFeature`,
`SearchFilterProfile`, `SearchFilterScenePOI`, and `SearchFilterCountry`. The other six
return an empty set instead of raising, so an empty result means the filter is not
supported here, not that your assets have no values.

`get_all_values` reads cache and indexed sources only. Service sources are skipped. Pass
`base_paths` to limit it to assets under given path prefixes.

### Example 4a: find scenes that contain both parking and speed bumps

```python
matches = asset_library.search(
    include_all=[SearchFilterScenePOI("parking"), SearchFilterScenePOI("speedbump")],
)
for asset_data in matches:
    print(asset_data.asset_path)
```

## Feature validation filter

### Example 5: find assets validated to have feature `FET_005` with version `1.0.0`

```python
matches = asset_library.search(
    include_all=[SearchFilterFeature("FET_005", version="1.0.0")],  # version is optional
)
for asset_data in matches:
    print(asset_data.asset_path)
```

## Natural-language queries

`SearchFilterLLMQuery` sends a complex free-text query to the search service, which parses it into
a description plus structured filters. This lets one string express what would otherwise require
several filters, including constraints the library has no filter for.

Requires a service source whose deployment exposes the `/llm_parse/query` route. If the parse
endpoint lives elsewhere, pass its full URL when registering the source:

```python
asset_library.add_service_source(service_endpoint, llm_parse_url="https://parser.example.com/llm_parse/query")
```

The service credentials are sent to that URL too. If parsing is unavailable there, the search
falls back to a phrase search as usual.

### Example 6: describe the query instead of building it from filters

```python
matches = asset_library.search(
    include_all=[SearchFilterLLMQuery("robot with Isaac profile")],
)
search_metadata = matches.search_metadata
for asset_data in matches:
    print(f"{asset_data.metadata.relevance_score:.2f}: {asset_data.asset_path}")
```

The service interprets that as the description `"robot"` plus a filter on the validation profile.

### Seeing how the query was interpreted

A natural-language query can change the search in ways you did not ask for, so the parse is
reported back once for the whole search in `search_metadata.llm_parse_result`. Check the constraints the service understood but could not
enforce. Without that check, a query asking for a license or a file size looks like it
worked. In fact the service dropped that clause:

```python
parse = search_metadata.llm_parse_result or {}

for f in parse.get("interpreted_query", {}).get("filters", []):
    print(f"filtered on {f['field']} {f['operator']} {f['value']}")
for constraint in parse.get("unmapped_constraints", []):
    print(f"NOT enforced: {constraint['text']} -- {constraint['note']}")
```

For `"warehouse shelves with rigid body physics under 100MB"` against a deployment that indexes
neither physics nor file size, that prints two `NOT enforced` lines and no filters: the search was
really just `"warehouse shelves"`.

### How it combines with other filters

A parsed query **replaces** the other include filters for the service request. Put your
constraints in the query text, not beside it:

- Other filters in `include_all` / `include_any` are ignored for the service request, and each one
  is named in a warning.
- `exclude_all` / `exclude_any` still apply. Exclusions are a separate axis the parsed query may
  not cover.
- `SearchFilterRelevance` still applies, because it filters the returned results rather than the
  request.
- `SearchFilterPhrase` is dropped in favor of the parsed query, with a warning, even when the two
  filters are in different include lists.
- Cache and indexed sources are unaffected and keep evaluating every filter normally. Since
  `SearchFilterLLMQuery` never matches a local asset, put it in `include_any` when you want local
  sources to contribute to the same search.
- `SearchFilterLLMQuery` and `SearchFilterPhrase` are only valid in `include_all` / `include_any`.
  Passing either in an exclude list is ignored with a warning: a parsed query or phrase cannot be
  negated.

A deployment that cannot parse queries falls back to a plain `SearchFilterPhrase`. The
other filters then apply as usual, so the search still returns useful results.

Constraints the service understood but could not enforce are reported as warnings through
`log_func` rather than failing the search.
