Skip to content

Commit

Permalink
fix: VectorCache from Json parse error in sync command
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnfluegge committed Jan 13, 2024
1 parent 3e4ed70 commit 02d9d68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions codeqai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def run():
vector_store.sync_documents(documents)
save_vector_cache(vector_store.vector_cache, f"{repo_name}.json")
spinner.stop()
print("⚙️ Vector store synced with current git checkout.")

llm = LLM(
llm_host=LlmHost[config["llm-host"].upper().replace("-", "_")],
Expand All @@ -156,6 +157,8 @@ def run():
console = Console()
while True:
choice = None
if args.action == "sync":
break
if args.action == "search":
search_pattern = input("🔎 Enter a search pattern: ")
spinner = yaspin(text="🤖 Processing...", color="green")
Expand Down
10 changes: 7 additions & 3 deletions codeqai/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import platform
from pathlib import Path
from typing import Dict


class VectorCache:
Expand All @@ -11,7 +12,7 @@ def __init__(self, filename, vector_ids, commit_hash):
self.commit_hash = commit_hash

@classmethod
def from_json(cls, json_data):
def from_json(cls, json_data) -> "VectorCache":
filename = json_data.get("filename")
vector_ids = json_data.get("vector_ids", [])
commit_hash = json_data.get("commit_hash", "")
Expand All @@ -25,9 +26,12 @@ def to_json(self):
}


def load_vector_cache(filename):
def load_vector_cache(filename) -> Dict[str, VectorCache]:
with open(get_cache_path() + "/" + filename, "r") as vector_cache_file:
vector_cache = json.load(vector_cache_file, object_hook=VectorCache.from_json)
vector_cache_json = json.load(vector_cache_file)
vector_cache = {}
for key, value in vector_cache_json.items():
vector_cache[key] = VectorCache.from_json(value)
return vector_cache


Expand Down
7 changes: 0 additions & 7 deletions tests/vector_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,12 @@ def test_sync_documents(modified_vector_entries, vector_entries, vector_cache):
assert len(vector_store.db.index_to_docstore_id) == 4
vector_store.vector_cache = vector_cache

for id in vector_store.db.index_to_docstore_id.values():
print(vector_store.db.docstore.search(id))

for vector_id in vector_store.db.index_to_docstore_id.values():
vector_store.vector_cache[
vector_store.db.docstore.search(vector_id).metadata["filename"]
].vector_ids.append(vector_id)
vector_store.sync_documents(modified_vector_entries)

print("After sync")
for id in vector_store.db.index_to_docstore_id.values():
print(vector_store.db.docstore.search(id))

assert len(vector_store.db.index_to_docstore_id) == 5

for vector_id in vector_store.db.index_to_docstore_id.values():
Expand Down

0 comments on commit 02d9d68

Please sign in to comment.