💡 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
Support pulling attribute data in graph.scan, closes #849
davidmezzetti4e5331e6411e
diff --git a/src/python/txtai/graph/networkx.py b/src/python/txtai/graph/networkx.pyindex b838e244..821d9f0a 100644--- a/src/python/txtai/graph/networkx.py+++ b/src/python/txtai/graph/networkx.py@@ -43,13 +43,16 @@ class NetworkX(Graph):def count(self):return self.backend.number_of_nodes()- def scan(self, attribute=None):- # Nodes containing an attribute+ def scan(self, attribute=None, data=False):+ # Full graph+ graph = self.backend++ # Filter graph to nodes having a specified attributeif attribute:- return nx.subgraph_view(self.backend, filter_node=lambda x: attribute in self.node(x))+ graph = nx.subgraph_view(self.backend, filter_node=lambda x: attribute in self.node(x))- # Return all nodes- return self.backend+ # Return either list of matching ids or tuple of (id, attribute dictionary)+ return graph.nodes(data=True) if data else graphdef node(self, node):return self.backend.nodes.get(node)diff --git a/src/python/txtai/graph/rdbms.py b/src/python/txtai/graph/rdbms.pyindex 564575aa..5397dc4e 100644--- a/src/python/txtai/graph/rdbms.py+++ b/src/python/txtai/graph/rdbms.py@@ -50,13 +50,14 @@ class RDBMS(NetworkX):# Return NetworkX compatible backendreturn self.graph.nx- def scan(self, attribute=None):+ def scan(self, attribute=None, data=False):if attribute:for node in self.backend:- if attribute in self.node(node):- yield node+ attributes = self.node(node)+ if attribute in attributes:+ yield (node, attributes) if data else nodeelse:- yield from super().scan(attribute)+ yield from super().scan(attribute, data)def load(self, path):# Create graph instance