Skip to content

Commit

Permalink
chore: fix missing cache directory in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnfluegge committed Jan 14, 2024
1 parent fa1fe91 commit 4f928c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion codeqai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def run():
)

# check if faiss.index exists
if not os.path.exists(os.path.join(get_cache_path(), f"{repo_name}_faiss.bytes")):
if not os.path.exists(os.path.join(get_cache_path(), f"{repo_name}.faiss.bytes")):
spinner = yaspin(text="🔧 Parsing codebase...", color="green")
files = repo.load_files()
documents = codeparser.parse_code_files(files)
Expand Down
6 changes: 3 additions & 3 deletions codeqai/vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def load_documents(self):
spinner = yaspin(text="💾 Loading vector store...", color="green")
spinner.start()
with open(
os.path.join(get_cache_path(), f"{self.name}_faiss.bytes"), "rb"
os.path.join(get_cache_path(), f"{self.name}.faiss.bytes"), "rb"
) as file:
index = file.read()

Expand All @@ -38,7 +38,7 @@ def index_documents(self, documents: list[Document]):
self.db = FAISS.from_documents(documents, self.embeddings)
index = self.db.serialize_to_bytes()
with open(
os.path.join(get_cache_path(), f"{self.name}_faiss.bytes"), "wb"
os.path.join(get_cache_path(), f"{self.name}.faiss.bytes"), "wb"
) as binary_file:
binary_file.write(index)
# Create vector cache
Expand Down Expand Up @@ -137,7 +137,7 @@ def sync_documents(self, documents: list[Document]):

index = self.db.serialize_to_bytes()
with open(
os.path.join(get_cache_path(), f"{self.name}_faiss.bytes"), "wb"
os.path.join(get_cache_path(), f"{self.name}.faiss.bytes"), "wb"
) as binary_file:
binary_file.write(index)
spinner.stop()
Expand Down
5 changes: 5 additions & 0 deletions tests/vector_store_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from pathlib import Path

import pytest
from langchain.embeddings import FakeEmbeddings

from codeqai.cache import get_cache_path
from codeqai.vector_store import VectorStore


@pytest.mark.usefixtures("vector_entries")
def test_index_documents(vector_entries):
Path(get_cache_path()).mkdir(parents=True, exist_ok=True)
embeddings = FakeEmbeddings(size=1024)
vector_store = VectorStore(name="test", embeddings=embeddings)
vector_store.index_documents(vector_entries)
Expand All @@ -31,6 +35,7 @@ def test_index_documents(vector_entries):

@pytest.mark.usefixtures("modified_vector_entries", "vector_entries", "vector_cache")
def test_sync_documents(modified_vector_entries, vector_entries, vector_cache):
Path(get_cache_path()).mkdir(parents=True, exist_ok=True)
embeddings = FakeEmbeddings(size=1024)
vector_store = VectorStore(name="test", embeddings=embeddings)
vector_store.index_documents(vector_entries)
Expand Down

0 comments on commit 4f928c0

Please sign in to comment.