Quick start

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.

Installation

First, install the sdk via your package manager:

Node.js | Python

Usage

Next, import it in your project:

import IndexClient from "@indexnetwork/sdk"

Create an instance of IndexClient:

const indexClient = new IndexClient({
  domain: "index.network",
  network: "ethereum", // Provide your network
  wallet, // Wallet that interacts
});

Authenticate it. Check out Authentication for details and explanation on how to initiate a session.

await indexClient.authenticate(); 

Creating an Index

We're ready. Now, let's create an Index with a title.

const indexId = await indexClient.createIndex({
  title: "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.

const webPageId = await indexClient.crawlWebPage({
  title: "Post medium publishing",
  url: "http://www.paulgraham.com/publishing.html"
});

await indexClient.addItemToIndex(indexId, webPageId);

Your index is now ready for interaction! Querying the index is straightforward:

const queryResponse = await indexClient.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
});

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",
    }
  ]
}

Last updated