Deep Research

Smart Search SDK supports advanced deep research using the Sonar and Assafelovic engines, with both POST and WebSocket interfaces. These methods allow asynchronous, long-form, or real-time research execution.

chevron-rightInitializationhashtag

Environment Setup

Make sure your environment variables are configured correctly in the .env file:

Update your environment configuration file as shown below:

SMARTSEARCH_BASE_URL=<your-api-url>
SMARTSEARCH_TOKEN=<your-auth-token>

Web Socket Initialization

Before using the WebSocket Function, ensure that you have initialized a DummyWebSocket or your own WebSocket implementation. The WebSocket is crucial for receiving real-time data from the engine. Here's an outline of what you need to do:

  • Initialize a WebSocket instance: Create an instance of DummyWebSocket or your custom WebSocket class.

  • Pass the WebSocket to the research client: When invoking the deep_research method, include this WebSocket instance in the input_data.

Here is the sample code for Dummy WebSocket. Ensure your web socket align with this structure.

class DummyWebSocket:
    def __init__(self):
        self.sent_messages = []

    async def send(self, message):
        print(f"[DummyWebSocket] Sent: {message}")
        self.sent_messages.append(message)

    async def recv(self):
        print("[DummyWebSocket] Receiving dummy message...")
        return json.dumps(
            {
                "status": "success",
                "message": "This is a dummy response.",
                "data": {"query": "Simulated Deep Research Result"},
            }
        )

    async def close(self):
        print("[DummyWebSocket] Closed.")

Initialize the Deep Research Client

from smartsearch.deep_research.client import SmartSearchDeepResearchClient

client = SmartSearchDeepResearchClient(
    base_url=os.getenv("SMARTSEARCH_BASE_URL"),
    cache_manager=cache_manager
)

Authenticate with Token

await client.authenticate(token=os.getenv("SMARTSEARCH_TOKEN"))

Must be called once before making any search requests.


Usage

  1. Sonar Deep Research (POST)

Perform deep research via the Sonar engine using a standard POST request.

Parameters:

Key
Type
Description

type

enum

Use ResearchType.POST_SONAR

query

string

The topic or question to analyze


  1. Sonar Deep Research (WebSocket)

Enable real-time result streaming using Sonar via WebSocket.

Parameters:

Key
Type
Description

type

enum

Use ResearchType.WS_SONAR

query

string

Query for research

websocket

DummyWebSocket

An async-compatible WebSocket handler


  1. Assafelovic Deep Research (POST)

Run in-depth analysis using the Assafelovic engine through POST.

Parameters:

Key
Type
Description

type

enum

Use ResearchType.POST_ASSAFELOVIC

query

string

Query or topic to be researched


  1. Assafelovic Deep Research (WebSocket)

Use WebSocket to stream live responses from the Assafelovic engine.

Parameters:

Key
Type
Description

type

enum

Use ResearchType.WS_ASSAFELOVIC

query

string

Research query

websocket

DummyWebSocket

WebSocket implementation to receive live results


Full Code Snippet

chevron-rightSonar Deep Research (POST)hashtag
chevron-rightSonar Deep Research (WebSocket)hashtag
chevron-rightAssafelovic Deep Research (POST)hashtag
chevron-rightAssafelovic Deep Research (WebSocket)hashtag

Last updated