Metadata-Version: 2.5
Name: smartsearch-ai
Version: 4.7.0
Summary: Python SDK for SmartSearch AI project search, Workplace and user provisioning
Project-URL: Homepage, https://github.com/smartsearch-ai/smartsearch-ai-python
Project-URL: Repository, https://github.com/smartsearch-ai/smartsearch-ai-python
Project-URL: Examples, https://github.com/smartsearch-ai/smartsearch-ai-integration-examples
Author: Weblink Technologies
License: SmartSearch AI SDK and Examples License
        
        Copyright (c) 2026 Weblink Technologies LLC. All rights reserved.
        
        This license covers the source code, documentation and other files in this
        repository (the "Software"). "SmartSearch AI" means the SmartSearch AI services
        provided by Weblink Technologies LLC ("Weblink"). "Account" means a SmartSearch AI
        account or agreement you hold with Weblink.
        
        1. Permission. While you hold an active Account, Weblink grants you a
           non-exclusive, non-transferable, non-sublicensable, royalty-free license to
           use, copy and modify the Software solely to build, test and run your own
           applications that connect to SmartSearch AI.
        
        2. Your applications. You may include the Software, or code derived from it, in
           your own applications that connect to SmartSearch AI, and run those
           applications for your own organization or to provide your services.
        
        3. No redistribution. You may not distribute, publish, sell, lease or
           sublicense the Software or any modified version of it on its own, as a
           library, as a template, or in source form, to anyone outside your
           organization.
        
        4. Restrictions. You may not use the Software (a) with any service other than
           SmartSearch AI; (b) to build or support a product that competes with
           SmartSearch AI; or (c) to probe, reverse engineer or bypass the security or
           usage limits of SmartSearch AI.
        
        5. Ownership. Weblink keeps all rights, title and interest in the Software and
           in SmartSearch AI. No rights are granted except those stated here.
        
        6. No warranty. The Software is provided "AS IS", without warranty of any kind,
           express or implied, including merchantability, fitness for a particular
           purpose and non-infringement.
        
        7. Limitation of liability. To the maximum extent permitted by law, Weblink is
           not liable for any claim, damages or other liability arising from or
           related to the Software or its use.
        
        8. Termination. This license ends automatically when your Account ends or when
           you breach these terms. You must then stop using the Software and delete
           your copies.
        
        9. Governing law. This license is governed by the laws of the State of Texas, United States.
        
        Questions about this license: production@smartsearchtools.com
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.27
Requires-Dist: pydantic<3,>=2.6
Description-Content-Type: text/markdown

# SmartSearch AI SDK for Python

Version **4.7.0** targets SmartSearch platform **4.7.0**. Python 3.10 or later is required.
This source version does not establish PyPI availability or live deployment qualification.
Maintainers: see [PyPI publishing setup and release steps](docs/PUBLISHING.md).

From a checkout of this version:

```bash
python -m pip install .
```

## Workplace search, answers and chat

The SDK calls the public API through your Gateway `api_url`. Workspace configuration,
membership, document permissions and agentic licensing still apply.

All routes below are `POST /workspace/v1/workspaces/{workspace_id}/...`.

| SDK method | Route | Server behavior |
|---|---|---|
| `workplace().search(...)` | `/search` | Regular retrieval with sources; forces `retrieval_only` |
| `workplace().query(...)` | `/query` | Agentic query; defaults to `retrieval_only`; set `Mode.ANSWER` for an answer |
| `workplace().chat(...)` | `/chat` | Conversational answer; forces `answer`; reuse returned `session_id` |
| `workplace().stream_query(...)` | `/query` | Same query modes, with SSE |
| `workplace().stream_chat(...)` | `/chat` | Conversational answer with SSE |

`query(...)` does **not** select answer mode automatically. The SDK forwards the request's
mode; `/search` and `/chat` enforce their modes on the server. Streaming methods set
`options.stream=true` and `Accept: text/event-stream`; buffered methods request JSON.

```python
import os
from smartsearch_ai import Mode, SmartSearchAi, WorkspaceQueryRequest

with SmartSearchAi(
    api_url=os.environ["SMARTSEARCH_API_URL"],
    admin_url=os.environ["SMARTSEARCH_ADMIN_URL"],
    auth_url=os.environ["SMARTSEARCH_AUTH_URL"],
    realm=os.environ["SMARTSEARCH_REALM"],
    client_id=os.environ["SMARTSEARCH_CLIENT_ID"],
    client_secret=os.environ["SMARTSEARCH_CLIENT_SECRET"],
    read_timeout=120,
) as client:
    workspace_id = os.environ["SMARTSEARCH_WORKSPACE_ID"]
    workplace = client.workplace()

    retrieved = workplace.search(workspace_id, WorkspaceQueryRequest(query="refund policy"))
    print(retrieved.body)

    answered = workplace.query(
        workspace_id, WorkspaceQueryRequest(query="What is the refund policy?", mode=Mode.ANSWER)
    )
    print(answered.body)

    first = workplace.chat(workspace_id, WorkspaceQueryRequest(query="Explain the refund policy."))
    followup = workplace.chat(workspace_id, WorkspaceQueryRequest(
        query="Does that include subscriptions?", session_id=first.body["session_id"]
    ))
    print(followup.body)

    with workplace.stream_query(workspace_id, WorkspaceQueryRequest(
        query="Summarize the policy.", mode=Mode.ANSWER
    )) as stream:
        for event in stream:
            print(event.event, event.payload)
        print(stream.result.body)  # Authoritative terminal response after run.completed.
```

Use `stream_chat(...)` with `session_id` for streaming conversation turns. Close streams with
`with`; the SDK raises `SmartSearchError` for failed or incomplete streams. Buffered
`WorkspaceResult.body` and streamed result bodies preserve the server's JSON fields.

The equivalent public API answer request uses the same explicit mode:

```bash
curl --fail-with-body "$SMARTSEARCH_API_URL/workspace/v1/workspaces/$SMARTSEARCH_WORKSPACE_ID/query" \
  -H "Authorization: Bearer $SMARTSEARCH_ACCESS_TOKEN" \
  -H 'Content-Type: application/json' -H 'Accept: application/json' \
  --data '{"query":"What is the refund policy?","mode":"answer"}'
```

## Optional retrieval settings and caller vectors

Version 4.7.0 adds typed `SearchStrategyConfig` and `QueryEmbedding`. Omit the whole strategy
block to use agent/Workspace defaults. A supplied block does not guarantee per-field
inheritance. Existing requests keep their wire format.

```python
from smartsearch_ai import QueryEmbedding, QueryOptions, SearchStrategyConfig, WorkspaceQueryRequest

request = WorkspaceQueryRequest(
    query="refund policy",
    search_strategy_config=SearchStrategyConfig(
        max_variants=3,
        source_type_weights={"pdf": 1.5},
        query_expansion_enabled=True,
        fanout_compiler_version="workspace_typed_fanout_v2",
    ),
)

# Only for a CALLER_VECTORS Workspace configured for this exact model and vector contract.
caller_vector_request = WorkspaceQueryRequest(
    query="refund policy",
    options=QueryOptions(embedding=QueryEmbedding(
        model_id="your-configured-model", model_revision="your-configured-revision",
        shape=[2], values=[0.6, 0.8],  # Replace with the actual model output and dimensions.
    )),
)
```

`SearchStrategyConfig` also supports `enabled`, `freshness_boost_enabled`,
`authority_boost_enabled`, `coverage_selector_enabled` and `max_keyword_expansions`.
Compiler values are `workspace_typed_fanout_v1` or `workspace_typed_fanout_v2`.
Source weights require nonblank keys and finite numbers. Effective strategy limits remain
server-owned.

Embedding values must be a nonempty, finite, rank-one numeric vector within float32 range.
Optional `shape` must equal `[len(values)]`. Model identity, revision (including omission),
dimensions and normalization must match the Workspace's immutable contract; the server
validates that contract. Managed-embedding and lexical-only Workspaces reject caller vectors.
Metric, normalization and target field cannot be overridden. Unknown fields, identity/security
overrides, internal query vectors and server-owned guardrails are not exposed by these models.

These additions cover the public query request fields above, not every platform management API.
Offline wire-contract tests do not establish live authorization, model readiness or deployment
compatibility; qualify those against your configured Gateway and Workspace before release use.

## Registering users

`users().submit_job(...)` registers users through an integration that an administrator set up in SmartSearch
(this SDK cannot create one). Users are created in SmartSearch's sign-in realm either way:

- **Invite** (`KEYCLOAK_INVITE`): each user gets an email to set a SmartSearch password. Send `EnsureItem` without
  `external_identity`.
- **Federated** (`KEYCLOAK_FEDERATED`): each user is linked to their existing account at your identity provider.
  Every `EnsureItem` must carry `external_identity=ExternalIdentity(subject=..., username=...)`.

Named codes (`SmartSearchError.code`, and the code of a failed job item): `INTEGRATION_NOT_FOUND`,
`EXTERNAL_IDENTITY_REQUIRED`, `EXTERNAL_IDENTITY_NOT_SUPPORTED`, importable from `smartsearch_ai`.
