Index Network API allows you to interact with our platform and build products leveraging our services. Below, you will find detailed information about the available endpoints, their purposes, and how to use them.
You can either use the API directly or the client available. Here is a quick start to discover it.
Using Index Client SDK
The Index Network offers an SDK to facilitate various operations on our platform. In this example, we'll demonstrate how to authenticate, create an Index, and add an Item to it.
Index is a fundamental component of the Index Network, designed to facilitate context management and enable semantic interoperability within your system. It serves as a structured way to organize and store data related to specific contexts.
Item represents a graph node within an Index. It provides a standardized approach to representing and managing various types of data.
constindexClient=newIndexClient({ domain:"index.network", network:"ethereum",// Provide your network wallet,// Wallet that interacts});
index_client =IndexClient( domain="index.network", wallet=your_wallet_object, # Provide your wallet instance network="ethereum"# Specify the network you're working on)
Authenticate it. Check out Authentication for details and explanation on how to initiate a session.
awaitindexClient.authenticate();
index_client.authenticate()
Creating an Index
We're ready. Now, let's create an Index with a title.
constindexId=awaitindexClient.createIndex({ title:"Future of publishing",});
index_id = client.create_index("Future of publishing")
Voilà, now you have a truly decentralized index to interact with! Though it's empty, which means we need to create and add an Item into it so we can interact. Let's do that.
constwebPageId=awaitindexClient.crawlWebPage({ title:"Post medium publishing", url:"http://www.paulgraham.com/publishing.html"});awaitindexClient.addItemToIndex(indexId, webPageId);
Your index is now ready for interaction! Querying the index is straightforward:
constqueryResponse=awaitindexClient.chat({ id:uuidv4(),// Provide a unique chat id for the query messages: [ { content:"How do you evaluate a startup?", role:"user", }, ], indexes: [indexId] // You can add all the indexes of a user as well});
import uuidchat_id =str(uuid.uuid4())messages = [{"content":"How do you evaluate a startup?","role":"user",},]response = index_client.chat(chat_id, messages, index_id)
The response should look something like this:
{ "response": "This article discusses the intricacies and challenges of publishing ... strategies for successful online publishing."
"sources": [ {"itemId":"kjzl6kcy...ii7z1anybovo","indexId":"rt38xm13...b2ca76w5ky27", } ]}