Skip to content

Commit 1fbc8ab

Browse files
authored
Index Name issue when using Weaviate (#87)
* fix small bugs * feat: make sure index name starts with a capital letter
1 parent 1dbff76 commit 1fbc8ab

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

service/router.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ async def get_documents(
4444
if not len(chunks):
4545
logger.error(f"No documents found for query: {payload.input}")
4646
return []
47-
is_structured = chunks[0].metadata.get("filetype") in STRUCTURED_DATA
47+
is_structured = (
48+
chunks[0].metadata and chunks[0].metadata.get("filetype") in STRUCTURED_DATA
49+
)
4850
reranked_chunks = []
4951
if is_structured and payload.interpreter_mode:
5052
async with CodeInterpreterService(

vectordbs/weaviate.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class WeaviateService(BaseVectorDatabase):
1515
def __init__(
1616
self, index_name: str, dimension: int, credentials: dict, encoder: BaseEncoder
1717
):
18+
# According to Weaviate's documentation, index names should start with a capital letter (https://weaviate.io/developers/weaviate/config-refs/schema#introduction)
19+
index_name = index_name[0].upper() + index_name[1:]
1820
# TODO: create index if not exists
1921
super().__init__(
2022
index_name=index_name,
@@ -77,7 +79,7 @@ async def query(self, input: str, top_k: int = 25) -> list[BaseDocumentChunk]:
7779
try:
7880
response = (
7981
self.client.query.get(
80-
class_name=self.index_name.capitalize(),
82+
class_name=self.index_name,
8183
properties=["document_id", "text", "doc_url", "page_number"],
8284
)
8385
.with_near_vector(vector)
@@ -88,7 +90,7 @@ async def query(self, input: str, top_k: int = 25) -> list[BaseDocumentChunk]:
8890
logger.error(f"Missing 'data' in response: {response}")
8991
return []
9092

91-
result_data = response["data"]["Get"][self.index_name.capitalize()]
93+
result_data = response["data"]["Get"][self.index_name]
9294
document_chunks = []
9395
for result in result_data:
9496
document_chunk = BaseDocumentChunk(

0 commit comments

Comments
 (0)