Skip to main content

Graph based Indexing

The aiXplain platform supports graph based indexing - a powerful retrieval-augmented generation (RAG) method that models relationships between concepts using graph structures. Graph-based indexing enhances information retrieval by connecting semantically related documents through embedded relationships, enabling multi-hop reasoning and deeper contextual understanding.

This guide walks you through the process of building and using a GraphRAG-powered index for intelligent, relation-aware semantic search.

Prepare Your Dataset

Begin by preparing your dataset in the form of plain text documents. Graph based indexing performs best with rich, well-structured information that can be connected semantically.

from aixplain.modules.model.record import Record

texts_about_ai = [
"AI stands for Artificial Intelligence, which refers to computer systems designed to perform tasks that typically require human intelligence.",
"Most modern AI systems rely on large datasets and powerful computing resources to learn patterns and make decisions.",
"Machine learning is a key subset of AI, where algorithms improve at tasks through experience and data.",
"AI is already being used in everyday technologies, such as smartphone assistants, recommendation systems, and spam filters.",
"AI cannot truly think or feel like a human; it operates based on mathematics, logic, and programmed algorithms.",
"Bias in AI systems can occur if the data used to train them is unbalanced or prejudiced.",
"AI has the potential to transform industries, including healthcare, finance, transportation, and education.",
"Current AI systems are generally specialized, meaning they excel at specific tasks but struggle with general intelligence.",
"Ethical issues related to AI include privacy, job displacement, and decision-making transparency.",
"Developing safe and trustworthy AI is an active area of research and concern for experts worldwide."
]

records = [Record(value=text, value_type="text") for text in texts_about_ai]

Create a Graph-based Index

To create a graph-based index, use the GraphRAGParams class to specify embedding and graph-specific configurations. This ensures the index is optimized for graph-based retrieval.

from aixplain.factories import IndexFactory
from aixplain.factories.index_factory.utils import AirParams, GraphRAGParams, VectaraParams, ZeroEntropyParams

graph_params = GraphRAGParams(
name="AI GraphRAG Index",
description="A knowledge graph of AI concepts"
)

index_model_graphrag = IndexFactory.create(params=graph_params)

Insert Data into the Index

Once your index is created, insert your records using upsert(). For GraphRAG, single inserts or small batches are often more reliable during indexing.

``python index_model_graphrag.upsert(records)


## Count Records
Verify how many records have been successfully indexed:

```python
index_model_graphrag.count()

Run semantic queries across your index. The GraphRAG engine will retrieve contextually related information across the knowledge graph.

response = index_model_graphrag.search("Artificial intelligence")

Explore the results:

Top match

response.data

All ranked results with scores

response.details

Graph structure details

response.additional_fields["rawData"]

Delete an Index

When you're done with the index, you can remove it using:

index.delete()