💡 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
Keep node id 0 in graph path search results (#1335)
Mohammad Hijjawi4e2efa2cbc97
diff --git a/src/python/txtai/graph/networkx.py b/src/python/txtai/graph/networkx.pyindex fbaf581d..f45afc03 100644--- a/src/python/txtai/graph/networkx.py+++ b/src/python/txtai/graph/networkx.py@@ -130,7 +130,7 @@ class NetworkX(Graph):for value in column:if isinstance(value, list):# Path group- nodes.update([node for node in value if node and not isinstance(node, dict)])+ nodes.update([node for node in value if node is not None and not isinstance(node, dict)])elif isinstance(value, dict):# Nodes by id attributenodes.update(uid for uid, attr in self.scan(data=True) if attr["id"] == value["id"])diff --git a/test/python/testgraph.py b/test/python/testgraph.pyindex a6e08fa5..934b6b80 100644--- a/test/python/testgraph.py+++ b/test/python/testgraph.py@@ -557,6 +557,34 @@ class TestGraph(unittest.TestCase):)self.assertEqual(len(results[0]), 3)+ def testSearchGraphPath(self):+ """+ Test path search returning a graph keeps node id 0+ """++ graph = GraphFactory.create({})+ graph.initialize()++ # Build a path 0 -> 1 -> 2+ for uid in range(3):+ graph.addnode(uid, id=str(uid))++ graph.addedge(0, 1, weight=0.9)+ graph.addedge(1, 2, weight=0.8)++ # Run path search+ results = graph.search(+ """+ MATCH P=()-[]->()+ RETURN P+ """,+ 10,+ graph=True,+ )++ self.assertEqual(sorted(results.scan()), [0, 1, 2])+ self.assertEqual(results.edgecount(), 2)+def testSearchSkip(self):"""Test a SKIP clause with a similar clause