Skip to content

Commit

Permalink
Add caching for program loading
Browse files Browse the repository at this point in the history
  • Loading branch information
YoanSallami committed Oct 9, 2023
1 parent 4f1f75c commit f9c9ebe
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 13 deletions.
Empty file modified hybridagi/hybridstores/__init__.py
100644 → 100755
Empty file.
Empty file modified hybridagi/hybridstores/program_memory/__init__.py
100644 → 100755
Empty file.
32 changes: 19 additions & 13 deletions hybridagi/hybridstores/program_memory/base.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def verify_programs(
def add_programs(
self,
names: List[str],
programs: List[str]):
programs: List[str],
use_cache: bool = True):
"""Method to add programs"""
indexes = []
dependencies = {}
assert(len(programs) == len(names))
Expand All @@ -88,21 +90,25 @@ def add_programs(
for idx, program in enumerate(programs):
program_name = names[idx]
graph_program = self.create_graph(program_name)
try:
if self.exists(program_name):
graph_program.delete()
except Exception:
pass

graph_program.query(program)
chain = LLMChain(llm=self.llm, prompt=PROGRAM_DESCRIPTION_PROMPT)
program_description = chain.predict(program=program)
vector = np.array(
self.embedding.embed_query(text=program_description),
dtype=np.float32)
if not self.exists(program_name) or not use_cache:
chain = LLMChain(llm=self.llm, prompt=PROGRAM_DESCRIPTION_PROMPT)
program_description = chain.predict(program=program)
vector = np.array(
self.embedding.embed_query(text=program_description),
dtype=np.float32)
params = {"program_name": program_name, "vector": list(vector)}
self.query('MERGE (n:Program {name:"$program_name"'+
', description:vector32f($vector)})',
params = params)
else:
params = {"program_name": program_name}
self.query('MATCH (n:Program {name:"$program_name"})'+
'-[r:DEPENDS_ON]->(m) DELETE r')
self.set_content(program_name, program)
params = {"program_name": program_name, "vector": list(vector)}
self.query('MERGE (n:Program {name:"$program_name"'+
', description:vector32f($vector)})',
params = params)
result = graph_program.query('MATCH (n:Program) RETURN n')
dependencies[program_name] = []
if len(result.result_set) > 0:
Expand Down
Empty file modified hybridagi/hybridstores/program_memory/program_memory.py
100644 → 100755
Empty file.
Empty file modified hybridagi/hybridstores/program_memory/prompt.py
100644 → 100755
Empty file.
Empty file modified hybridagi/tools/list_programs.py
100644 → 100755
Empty file.
Empty file modified hybridagi/tools/load_programs.py
100644 → 100755
Empty file.
Empty file modified hybridagi/tools/program_search.py
100644 → 100755
Empty file.
Empty file modified models/README.md
100644 → 100755
Empty file.
Empty file modified tests/interpreter/data/test_program.cypher
100644 → 100755
Empty file.

0 comments on commit f9c9ebe

Please sign in to comment.