Open bk39rice opened 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.
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'?