Skip to content

Commit

Permalink
Added warning if struct_id is not mentioned in aget_index_struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
dishaprakash committed Nov 27, 2024
1 parent 811b450 commit 11fb1ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/llama_index_alloydb_pg/async_index_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import json
from typing import List, Optional
import warnings

from llama_index.core.constants import DATA_KEY
from llama_index.core.data_structs.data_structs import IndexStruct
Expand Down Expand Up @@ -174,6 +175,7 @@ async def aget_index_struct(
structs = await self.aindex_structs()
if len(structs) == 1:
return structs[0]
warnings.warn("No struct_id specified and more than one struct exists.")
return None
else:
query = f"""SELECT * from "{self._schema_name}"."{self._table_name}" WHERE index_id = '{struct_id}';"""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_async_index_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import uuid
from typing import Sequence
import warnings

import pytest
import pytest_asyncio
Expand Down Expand Up @@ -153,3 +154,16 @@ async def test_aindex_structs(self, index_store):
assert index_dict_struct in indexes
assert index_list_struct in indexes
assert index_graph_struct in indexes

async def test_warning(self, index_store):
index_dict_struct = IndexDict()
index_list_struct = IndexList()

await index_store.aadd_index_struct(index_dict_struct)
await index_store.aadd_index_struct(index_list_struct)

with warnings.catch_warnings(record=True) as w:
index_struct = await index_store.aget_index_struct()

assert len(w) == 1
assert "No struct_id specified and more than one struct exists." in str(w[-1].message)

0 comments on commit 11fb1ba

Please sign in to comment.