💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Code cleanup
davidmezzetti2f11f93743b7
diff --git a/src/python/txtai/graph/base.py b/src/python/txtai/graph/base.pyindex 71b33e0d..32184d75 100644--- a/src/python/txtai/graph/base.py+++ b/src/python/txtai/graph/base.py@@ -536,24 +536,21 @@ class Graph:# Unpack node and score, if availablenode, score = node if isinstance(node, tuple) else (node, None)- # Skip ids that don't exist in this graph- nodeattrs = self.node(node)- if nodeattrs is None:- continue-- # Add nodes- graph.addnode(node, **nodeattrs)-- # Add score if present- if score is not None:- graph.addattribute(node, "score", score)-- # Add edges- edges = self.edges(node)- if edges:- for target, attributes in self.edges(node).items():- if target in nodeids:- graph.addedge(node, target, **attributes)+ # Add node if it exists+ if self.hasnode(node):+ # Add nodes+ graph.addnode(node, **self.node(node))++ # Add score if present+ if score is not None:+ graph.addattribute(node, "score", score)++ # Add edges+ edges = self.edges(node)+ if edges:+ for target, attributes in self.edges(node).items():+ if target in nodeids:+ graph.addedge(node, target, **attributes)# Filter categories and topicsif self.topics:diff --git a/test/python/testann/testdense.py b/test/python/testann/testdense.pyindex 59ff6ef0..2280c879 100644--- a/test/python/testann/testdense.py+++ b/test/python/testann/testdense.py@@ -407,6 +407,11 @@ class TestDense(unittest.TestCase):self.runTests("zvec", {"zvec": {"m": 16}})+ # Test invalid file path handled+ with self.assertRaises(FileNotFoundError):+ ann = ANNFactory.create({"backend": "zvec"})+ ann.load("non-exist-path")+def runTests(self, name, params=None, update=True):"""Runs a series of standard backend tests.diff --git a/test/python/testgraph.py b/test/python/testgraph.pyindex 4443aef4..3019d99d 100644--- a/test/python/testgraph.py+++ b/test/python/testgraph.py@@ -188,50 +188,6 @@ class TestGraph(unittest.TestCase):self.assertTrue(graph.hasedge(0))self.assertTrue(graph.hasedge(0, 1))- def testFilterUnknownId(self):- """- Test that filter() skips ids that don't exist in the graph instead of- crashing when unpacking self.node(node) (which returns None for a- missing node).- """-- graph = GraphFactory.create({})- graph.initialize()- graph.addnode(0, id="a", data="hello")- graph.addnode(1, id="b", data="world")- graph.addedge(0, 1)-- subgraph = graph.filter([0, 1, 99])-- self.assertTrue(subgraph.hasnode(0))- self.assertTrue(subgraph.hasnode(1))- self.assertFalse(subgraph.hasnode(99))- self.assertTrue(subgraph.hasedge(0, 1))-- def testInsertNoneTextIndexSync(self):- """- Test that a document with a present but None text/object field consumes an- indexid slot without creating a node, keeping later node ids in sync with- the real vector index offset (which increments on key presence, not on the- resolved value being non-None - see Transform.stream()).- """-- graph = GraphFactory.create({})- graph.initialize()-- documents = [- ("d0", {"text": "alpha content"}, None),- ("d1", {"text": None}, None),- ("d2", {"text": "gamma content"}, None),- ]- graph.insert(documents, index=0)-- # d1's slot (index 1) is consumed but has no node - d2 must land at index 2, not 1- self.assertTrue(graph.hasnode(0))- self.assertFalse(graph.hasnode(1))- self.assertTrue(graph.hasnode(2))- self.assertEqual(graph.node(2)["id"], "d2")-def testFilter(self):"""Test creating filtered subgraphs@@ -245,6 +201,11 @@ class TestGraph(unittest.TestCase):self.assertEqual(graph.count(), 3)self.assertEqual(graph.edgecount(), 2)+ # Validate non-existent node ids handled+ graph = graph.filter(range(len(self.data)))+ self.assertTrue(graph.hasnode(4))+ self.assertFalse(graph.hasnode(1))+def testFunction(self):"""Test running graph functions with SQL