Langchain

The Index Network SDK provides a robust solution for integrating your semantic index with the Langchain API. This integration is supported in both TypeScript and Python, enabling a seamless connection and enhanced interoperability between your applications and Langchain services. With the SDK, developers can effortlessly link their semantic indexes to the rich functionalities offered by Langchain, such as natural language processing, data retrieval, and AI-driven analytics. This documentation will guide you through the setup, configuration, and usage of the Index Network SDK to ensure a successful integration with Langchain, enhancing your applications with powerful semantic capabilities.

Usage:

Start by initializing the index vector store module from index-network-sdk

import IndexClient from "@indexnetwork/sdk";

const wallet = new Wallet(process.env.PRIVATE_KEY);
const indexClient = new IndexClient({
  domain: "index.network",
  network: "ethereum",
  wallet, // or session
});

await indexClient.authenticate();

const vectorStore = await indexClient.getVectorStore({
  embeddings: new OpenAIEmbeddings({
    openai_api_key: process.env.OPENAI_API_KEY,
    openai_model: "text-embedding-ada-002",
  }),
})

Use can you use it for utilizing in vector search, you can tr


const question = "What is Index Network?";
const res = await vectorStore.similaritySearch(question, 2);
console.log(JSON.stringify(res, null, 2));

/** Response
[
   {
      "pageContent": "\nWhat is Index Network\nIndex is a composable discovery protocol that allows to create  truly personalized and autonomous discovery experiences across the web.\nTo achieve this, Index provides a decentralized semantic index that eliminates data fragmentation, a composable discovery protocol that allows data to be queried from multiple sources, in a user-centric manner. On top of this, it provides a real-time environment for agents that facilitates integration with algorithms and services and ensures that information acquires a fluid, social, and autonomous structure.\nTo illustrate, here is an example of an agent message that’s possible using Index Network:\nBy storing vector embeddings on a decentralized knowledge graph, Index Network creates the first decentralized semantic index, introducing a new open layer to information discovery.\nAs part of an open ecosystem, Index is built with a strong commitment to decentralized standards to foster a non-fragmented information ecosystem. It operates with the new DID standard to provide decentralized identity functions for both humans and AI agents, and uses the DIDComm standard for secure communication.\n\nTo store data in a decentralized and composable manner, Index is built with ComposeDB of the Ceramic Network, which makes indexed data part of an open, composable data ecosystem. All data is stored on IPFS, enabling users to create, own, and store their data without relying on a third party.\nHow it works?\nLast modified \n10d ago",
      "metadata": {
         "indexCreatedAt": "2024-02-14T12:39:59.626Z",
         "indexId": "kjzl6kcym7w8y6f8dlytgaz45x9nksobo0umml0uomzx82c074rppq6qnabunkv",
         "indexOwnerDID": "did:pkh:eip155:175177:0x182590b8052072b9954B066ba5794E8eB5c67112",
         "indexTitle": "Index Network",
         "indexUpdatedAt": "2024-02-14T12:39:59.626Z",
         "webPageCreatedAt": "2024-02-14T12:40:03.493Z",
         "webPageId": "kjzl6kcym7w8y8npetqo72tg8uopsbykp384k8fuky4kjfb2s9dft2ooie7kr4x",
         "webPageTitle": "Index Network Documentation | What is Index Network",
         "webPageUpdatedAt": "2024-02-14T12:40:04.974Z",
         "webPageUrl": "https://docs.index.network/docs/overview/readme"
      }
   },
   {
      "pageContent": "\nIndex Network is live on testnet.\nThe human bridge between context and content\nIndex Network helps you to create composable discovery engines.\nDiscovery as a Network\nIndex is the discovery protocol in web3, which enables composable\nqueries across interoperable discovery engines.\nCreating a discovery ecosystem as a network promotes greater participation in\ndecentralized discovery and contributes to a diverse and inclusive web.\nCreate contextual discovery engines from your data\nFor any kind of content\nIndex products, articles, documents, NFTs, photos, videos, tweets and any other kind of content.\nFrom any source\nUpdate your indexes directly from the apps you use or stay up-to-date with the indexes you follow. [soon]\nCollaborate on two-person projects up to DAO-scale. Monetize independently.\nMultiplayer Indexes\nSpecify on-chain criteria like \"user must hold an NFT\" and the network will provide permission to those who meet those criteria.\nCreator Monetization\nMonetize indexes with your own terms by composing access control conditions [soon]\nUse cases\nDocumentation\nEnable builders to interact with technologies using composable discovery engines.\nAsk how to integrate multiple technologies\nBuild with real-time, verified knowledge\nJournalism\nUse composable indexes to provide readers navigate diverse narratives and viewpoints in news media, promoting a well-rounded understanding.\nCompare different perspectives, understand biases\nExplore historical context from verified sources\nAsk for facts by using fact-check indexes\nScience\nFacilitate collaboration and data sharing among researchers for decentralized scientific discovery.\nBridge gaps between different research fields\nConnect academia with industry partners\nEngage in scientific debate\nConsultancy\nAccess and compare insights from various consulting firms. Evaluate strategies, market analyses, and industry trends for informed decisions.\nExpose perspectives to multiple contexts\nEvaluate the business impacts of new technologies\nReview diverse perspectives on trends\nBrand + Tastemaker\nRedefine how taste-makers engage with brands and humans, shifting from specific brand curation to indexing personal taste for authentic recommendations.\nBlend taste with products\nCompose a style symphony that is uniquely yours\nUncover hidden brand synergies\nBuilt with open protocols\nBacked by\nStay up to date with our newsletter\nKeep up with us\nJoin our community to get support, provide feedback, or just to say hello on...",
      "metadata": {
         "indexCreatedAt": "2024-02-14T12:39:59.626Z",
         "indexId": "kjzl6kcym7w8y6f8dlytgaz45x9nksobo0umml0uomzx82c074rppq6qnabunkv",
         "indexOwnerDID": "did:pkh:eip155:175177:0x182590b8052072b9954B066ba5794E8eB5c67112",
         "indexTitle": "Index Network",
         "indexUpdatedAt": "2024-02-14T12:39:59.626Z",
         "webPageCreatedAt": "2024-02-14T12:40:24.042Z",
         "webPageId": "kjzl6kcym7w8y60baa2yb07s87kse3vtfk46nyxzny32gf8yyszxap8dgincdme",
         "webPageTitle": "index.network | Index Network | The human bridge between context and content.",
         "webPageUpdatedAt": "2024-02-14T12:40:24.233Z",
         "webPageUrl": "https://index.network/"
      }
   }
]
**/

Also you can utilize the vector store for Retrieval Augmented Generation (RAG) Pipelines as well

from langchain import hub
from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnablePassthrough

llm = ChatOpenAI(model="gpt-3.5-turbo-0125", api_key='YOUR_API_KEY')

# Retrieve and generate using the relevant snippets of the blog.
retriever = vectorstore.as_retriever()
prompt = hub.pull("rlm/rag-prompt")

def format_docs(docs):
    return "\\n\\n".join(doc.page_content for doc in docs)

rag_chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

rag_chain.invoke("What is Index Network?")

We provide a read-only vector store since the vectorstore updates done with indexClient object through ComposeDB. Therefore we restrict the add, update, delete functionality within ChromaDB client. You can see the resticted methods and the corresponding indexClient methods below.

ChromaDb FunctionIndex Client Function

add_documents

addItemToIndex

from_documents

createIndex & addItemToIndex

from_texts

createIndex & addItemToIndex

delete

deleteItemFromIndex

delete_collection

disownIndex

update

updateIndexor updateIndex

Last updated