run-llama / llama_index

LlamaIndex is a data framework for your LLM applications
https://docs.llamaindex.ai
MIT License
33.36k stars 4.67k forks source link

[Question]: Load pre-existing graph as knowledge graph index #12815

Open bk39rice opened 2 months ago

bk39rice commented 2 months ago

Question Validation

Question

What is best practice for loading a pre-existing graph as a knowledge graph index? Would it be the correct approach to manually insert the nodes and triplets using 'add_node' and 'upsert_triplet'?

dosubot[bot] commented 2 months ago

For loading a pre-existing graph into a knowledge graph index, using the add_node and upsert_triplet methods is indeed a correct approach. These methods allow for the manual insertion of nodes and the insertion or updating of triplets, respectively. Additionally, the upsert_triplet_and_node method can be particularly useful as it combines the functionality of both add_node and upsert_triplet, ensuring that both nodes and triplets are added to the knowledge graph efficiently.

If you're dealing with a large dataset, consider using the from_documents class method for bulk loading. This method is designed for creating an index from a sequence of documents, effectively transforming these documents into nodes and building the index in a more efficient manner.

These methods are part of the KnowledgeGraphIndex class and are designed to facilitate the inclusion of nodes and triplets into the knowledge graph, with support for embeddings to enhance the graph's capabilities. For detailed implementation, you can refer to the source code available in the LlamaIndex repository.

This approach should help you effectively load your pre-existing graph into the knowledge graph index. If you have further questions or need more details, feel free to ask.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.