-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Found duplicated primary key value Summer founders program, which violates the uniqueness constraint of the primary key column.[Bug]: #13754
Comments
To resolve the Here is an example of how to use this method: from llama_index.legacy.indices.knowledge_graph.base import KnowledgeGraphIndex
from llama_index.legacy.schema import TextNode
from llama_index.legacy.service_context import ServiceContext
# Create an instance of KnowledgeGraphIndex
index = KnowledgeGraphIndex([], service_context=ServiceContext())
# Define your triplets and nodes
triplets = [
("foo", "is", "bar"),
("hello", "is not", "world"),
("Jane", "is mother of", "Bob"),
]
nodes = [TextNode(text=str(tup)) for tup in triplets]
# Add triplets and nodes to the index
for triplet, node in zip(triplets, nodes):
index.upsert_triplet_and_node(triplet, node) This method ensures that duplicates are handled appropriately when adding triplets and nodes to the In the provided test cases, the from unittest.mock import patch
from llama_index.legacy.indices.knowledge_graph.base import KnowledgeGraphIndex
from llama_index.legacy.schema import TextNode
from llama_index.legacy.service_context import ServiceContext
@patch.object(KnowledgeGraphIndex, "_extract_triplets", side_effect=mock_extract_triplets)
def test_build_kg_manual(_patch_extract_triplets, mock_service_context):
index = KnowledgeGraphIndex([], service_context=mock_service_context)
tuples = [
("foo", "is", "bar"),
("hello", "is not", "world"),
("Jane", "is mother of", "Bob"),
]
nodes = [TextNode(text=str(tup)) for tup in tuples]
for tup, node in zip(tuples, nodes):
index.upsert_triplet_and_node(tup, node)
# Verify the nodes and triplets
docstore_nodes = index.docstore.get_nodes(list(index.index_struct.node_ids))
table_chunks = {n.get_content() for n in docstore_nodes}
assert len(table_chunks) == 3
assert "('foo', 'is', 'bar')" in table_chunks
assert "('hello', 'is not', 'world')" in table_chunks
assert "('Jane', 'is mother of', 'Bob')" in table_chunks
# Test inserting the same node twice
node = TextNode(text=str(("foo", "is", "bar")), id_="test_node")
index.upsert_triplet_and_node(tup, node)
index.upsert_triplet_and_node(tup, node) This test case demonstrates how the
|
Bug Description
Version
0.10.14
Steps to Reproduce
https://docs.llamaindex.ai/en/stable/examples/index_structs/knowledge_graph/KuzuGraphDemo/
only added
Relevant Logs/Tracbacks
The text was updated successfully, but these errors were encountered: