Skip to content

Commit 10f2519

Browse files
bigdata-bizhyeongyuy
andauthored
Fix OpenSearch NotFoundError when index doesn't exist (#300)
- Handle opensearchpy.exceptions.NotFoundError in size() method - Return 0 when index is not found instead of crashing - Fixes chat functionality when using OpenSearch vector store - Resolves issue #298 Co-authored-by: hyeongyuy <hyeongyu@hyeongyu-yeo.localdomain>
1 parent e459388 commit 10f2519

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llm-service/app/ai/vector_stores/opensearch.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def _find_dim(data_source_id: int) -> int:
112112

113113
def size(self) -> Optional[int]:
114114
os_client = self._low_level_client
115-
return int(os_client.count(index=self.table_name)["count"])
115+
try:
116+
return int(os_client.count(index=self.table_name)["count"])
117+
except opensearchpy.exceptions.NotFoundError:
118+
# Return 0 if index doesn't exist yet
119+
return 0
116120

117121
def delete(self) -> None:
118122
os_client = self._low_level_client

0 commit comments

Comments
 (0)