feat (process.py): The build_sorted_vertices_with_caching function is added to build the sorted vertices of the langchain object with caching. It also uses the memoize_dict decorator to cache the result. The function first builds the langchain object from the data graph, then iterates over the sorted vertices and updates the artifacts dictionary. This ensures that the artifacts are properly updated during the building process.
Both caching mechanisms improve the performance of building the langchain object and sorted vertices, reducing redundant computations and improving overall efficiency. The `build_langchain_object_with_caching` function now uses the `memoize_dict` decorator to cache the result of building the langchain object from the data graph. This improves performance by avoiding redundant computations when the same data graph is used multiple times.
This commit is contained in:
parent
8546843b0d
commit
e43cbdacb7
1 changed files with 17 additions and 0 deletions
|
|
@ -14,6 +14,23 @@ def build_langchain_object_with_caching(data_graph):
|
|||
return graph.build()
|
||||
|
||||
|
||||
@memoize_dict(maxsize=10)
|
||||
def build_sorted_vertices_with_caching(data_graph):
|
||||
"""
|
||||
Build langchain object from data_graph.
|
||||
"""
|
||||
|
||||
logger.debug("Building langchain object")
|
||||
graph = Graph.from_payload(data_graph)
|
||||
sorted_vertices = graph.topological_sort()
|
||||
artifacts = {}
|
||||
for vertex in sorted_vertices:
|
||||
vertex.build()
|
||||
if vertex.artifacts:
|
||||
artifacts.update(vertex.artifacts)
|
||||
return graph.build(), artifacts
|
||||
|
||||
|
||||
def build_langchain_object(data_graph):
|
||||
"""
|
||||
Build langchain object from data_graph.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue