Node.js SDK

Quick start

Index Network allows you to interact with our platform and build products leveraging our services. Below, you will find detailed information on how to use them.

Here's a quick start guide.

Using the Index Network Node.js SDK

The Python SDK provides various operations on our platform. This guide will walk you through setting up the SDK, authenticating, creating an Index, and adding an Item to it and finally interacting with it.

Installation

First, install the @indexnetwork/sdk via your preferred package manager:

yarn add @indexnetwork/sdk

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.

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);

Interacting with an Index

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
});

console.log("Query response:", queryResponse);

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