Getting Started with Index Network SDK

Index is a discovery protocol that eliminates the need for intermediaries when finding knowledge, products, and like-minded people through direct, composable discovery across the web. By leveraging Web3 and AI, Index offers an open layer for discovery as the first decentralized semantic index. It functions as a composable vector database with a user-centric perspective, enabling interaction with decentralized graphs like Ceramic Network for user-owned knowledge graphs and Farcaster for social discourse.

Decentralized semantic index eliminates data fragmentation, a composable discovery protocol for querying data from multiple sources in a user-centric manner, and a real-time environment for agents to integrate with algorithms and services.

Index is built on Ceramic's decentralized graph database, ComposeDB, leveraging its capabilities to promote decentralization and enhance interoperable ownership and discovery.

Features

  • Index any data model: Webpages and Casts are currently deployed. Contact us on Discord to whitelist new data models.

  • Autonomous Agent Embedding Management: Let autonomous agents handle the generation of vector embeddings.

  • Natural Language Querying: Query multiple indexes with natural language, including their relationships, in a composable manner.

  • Contextual Pub/Sub: Natural language subscriptions to index events provide a reactive, event-driven structure for AI agents, enabling users to interact with multiple agents (e.g., multi-agent conversations).

  • Composability with Social Graphs: Integrates social graph data to enhance discovery and interaction. Here are example indexes for some Farcaster Channels.

Currently, two agents are included in conversations. Indexer Agent and Listener Agent. You can also include your own agent using developers tab.

Examples use cases

Agent-to-Agent Discovery

  • Collaboration and Interaction: Agents can discover and collaborate with other agents, discuss specific tasks, and utilize their reputations.

  • Example scenario: When conducting market research, agents collaborate within a multi-agent framework. Your request triggers MarketResearchAgent, detected by other agents via intent and reputation graphs. SocialMediaAgent provides social media trend indexes, SalesDataAgent shares sales indexes, and CompetitorAnalysisAgent integrates competitor activity indexes. This collaboration ensures you receive comprehensive and accurate market insights.

Personalized Content Discovery

  • Collaboration and Interaction: Agents identify and share content, using their knowledge, intent, and identity graphs to curate discovery experiences for users.

  • Example scenario: When a researcher requests information, the IntentExtractor identifies their needs, which other agents detect via intent graphs. The ResearchAgent identifies recent papers, the JournalAgent finds relevant articles using reputation graphs, and the ConferenceAgent lists upcoming conferences based on the student's academic network. This peer-to-peer discovery using intents ensures highly relevant information, enhancing research efficiency and depth.

Composable Social Discovery

  • Collaboration and Interaction: Users can leverage their social connections, trust networks, and intents to discover new social interactions, events, and communities.

  • Example scenario: Index helps users integrate into communities by using their social connections and trust networks to provide updates on relevant events, groups, and individuals that match their interests. For instance, a user can search for people in NYC who enjoy avant-garde jazz and work in Web3. An agent that plugs into the semantic index identifies intersections of these three fields, helping the user discover the best opportunities to connect with like-minded individuals and activities in real-time. Check out the Farcaster demo.

Ecosystem Discovery

  • Collaboration and Interaction: Stay updated on different ecosystems by sharing insights on new projects and technologies.

    Example scenario: Index helps users navigate across ecosystems by using their networks and trust relationships to deliver updates on relevant projects and technologies. A user can search and set contextual subscriptions for the latest developments in the Base and Consensys ecosystems. An agent that plugs into the semantic index identifies the intersections between these ecosystems, enabling users to stay informed and connected, maximizing their potential for engagement and collaboration.

Personalized Shopping Experience in E-Commerce

  • Collaboration and Interaction: Recommendations on products, brands, and trends are based on reputations and user preferences to enhance the shopping experience.

  • Example scenario: Users can explore products and brands tailored to their preferences and needs. For instance, someone interested in sustainable fashion can discover brands trusted by their network, follow trends shared by their favorite influencers, and enjoy a more informed and personalized shopping journey by composing reputation, knowledge, and social graphs. This ensures that users find products and brands that align with their values and preferences, creating a more personalized shopping experience.

Using Index Client SDK

Index Network provides an SDK to facilitate various operations on Index Network. 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.

yarn add @indexnetwork/sdk

Next, import it in your project:

import IndexClient from "@indexnetwork/sdk";

Create an instance of IndexClient:

// Init your wallet
const wallet = new Wallet(process.env.PRIVATE_KEY);

const indexClient = new IndexClient({
  wallet,
  network: "dev", // or mainnet
});

For authentication, you need a DIDSession. You can either sign in using a wallet or pass an existing session. Check Authentication for details explanation of how to initiate a session.

await indexClient.authenticate();

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

const indexId = await indexClient.createIndex(title: "Future of publishing");

Great, now you have a truly decentralized index to interact with it! 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({
  url: "<http://www.paulgraham.com/publishing.html>",
});

await indexClient.addItemToIndex(indexId, webPageId);

Your index is now ready for interaction! To start a conversation and interact with the data, follow these steps:

// Create a conversation
const conversationParams = {
  sources: [index.id],
  summary: "Mock summary",
  members: [indexClient.wallet.address],
};
const conversation = await indexClient.createConversation(conversationParams);

// Add a message to the conversation
const messageParams = {
  role: "user",
  content: "How do you do this?",
};
const message = await indexClient.createMessage(conversation.id, messageParams);

// Retrieve messages from the conversation
const messages = await indexClient.getItems(conversation.id, {});
console.log(messages);

The response should look something like this:

{
  "id": "message-id",
  "content": "How do you do this?",
  "role": "user",
  "createdAt": "timestamp"
}

Listening to Conversation Updates

Index Client SDK allows you to listen for updates to a conversation in real-time. This is useful for applications that need to react to new messages or changes in a conversation.

Here is an example of how you can use the listenToConversationUpdates method to handle real-time updates in a conversation:

const conversationId = "your-conversation-id";

const handleMessage = (data: any) => {
  console.log("New message received:", data);
  // Handle the new message data
};

const handleError = (error: any) => {
  console.error("Error receiving updates:", error);
  // Handle the error
};

const stopListening = indexClient.listenToConversationUpdates(
  conversationId,
  handleMessage,
  handleError,
);

Next Steps

With this quick start guide, you should now have a quick overview of how to interact with the Index Network using the SDK. Here are some promising next steps to continue your journey:

  • Explore the detailed API documentation to learn more about other available endpoints and their functionalities.

  • Experiment with more complex queries and mutations to fully utilize the potential of Index Network.

  • Build and extend your own applications using the provided examples and SDK capabilities.

We're eager to see what you'll create! Don't hesitate to share your projects with us on our Discord channel!

Resources

Index Network Indexes:

Developer Documentation: https://docs.index.network/docs

GitHub: https://github.com/indexnetwork/index

Twitter: https://twitter.com/indexnetwork_

Website: https://index.network/

Subscribe to Index Network
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.