Semantic Listener
This endpoint allows subscribers to listen for data that matches specific criteria defined semantically (using natural language queries) across various indexes. It supports complex queries, including filtering and sorting, to fine-tune the data stream received.
Listening to Index Updates
The Index Client SDK allows you to listen for updates to multiple indexes in real-time. This is useful for applications that need to react to new data events, using natural language.
Here is an example of how you can use the listenToIndexUpdates
method to handle real-time updates in a conversation:
const sources = ["did:pkh:eip155:1:0x1b9Aceb609a62bae0c0a9682A9268138Faff4F5f"];
const query = "if it is relevant to decentralized AI";
const handleMessage = (data: any) => {
console.log("New event received:", data);
// Handle the new message data
};
const handleError = (error: any) => {
console.error("Error receiving updates:", error);
// Handle the error
};
const stopListening = indexClient.listenToIndexUpdates(
sources,
query
handleMessage,
handleError,
);
Endpoints
This section provides details about the available API endpoints.
Query parameters
sourcesstring[]Required
List of sources to listen for updates.
querystringRequired
The query string to filter updates.
sessionstringRequired
The session identifier.
Responses
200
Updates are streamed as server-sent events.
text/event-stream
ResponsestringExample:
event: message data: {"id":"1","message":"Update received"}
400
Invalid request parameters.
500
Internal server error.
get
GET /api/discovery/updates HTTP/1.1
Host: dev.index.network
Accept: */*
event: message
data: {"id":"1","message":"Update received"}
Last updated