Skip to content

Commit

Permalink
Index Name issue when using Weaviate (#87)
Browse files Browse the repository at this point in the history
* fix small bugs

* feat: make sure index name starts with a capital letter
  • Loading branch information
elisalimli committed Mar 7, 2024
1 parent 1dbff76 commit 1fbc8ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion service/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ async def get_documents(
if not len(chunks):
logger.error(f"No documents found for query: {payload.input}")
return []
is_structured = chunks[0].metadata.get("filetype") in STRUCTURED_DATA
is_structured = (
chunks[0].metadata and chunks[0].metadata.get("filetype") in STRUCTURED_DATA
)
reranked_chunks = []
if is_structured and payload.interpreter_mode:
async with CodeInterpreterService(
Expand Down
6 changes: 4 additions & 2 deletions vectordbs/weaviate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class WeaviateService(BaseVectorDatabase):
def __init__(
self, index_name: str, dimension: int, credentials: dict, encoder: BaseEncoder
):
# According to Weaviate's documentation, index names should start with a capital letter (https://weaviate.io/developers/weaviate/config-refs/schema#introduction)
index_name = index_name[0].upper() + index_name[1:]
# TODO: create index if not exists
super().__init__(
index_name=index_name,
Expand Down Expand Up @@ -77,7 +79,7 @@ async def query(self, input: str, top_k: int = 25) -> list[BaseDocumentChunk]:
try:
response = (
self.client.query.get(
class_name=self.index_name.capitalize(),
class_name=self.index_name,
properties=["document_id", "text", "doc_url", "page_number"],
)
.with_near_vector(vector)
Expand All @@ -88,7 +90,7 @@ async def query(self, input: str, top_k: int = 25) -> list[BaseDocumentChunk]:
logger.error(f"Missing 'data' in response: {response}")
return []

result_data = response["data"]["Get"][self.index_name.capitalize()]
result_data = response["data"]["Get"][self.index_name]
document_chunks = []
for result in result_data:
document_chunk = BaseDocumentChunk(
Expand Down

0 comments on commit 1fbc8ab

Please sign in to comment.