Skip to content

Commit 72bc93d

Browse files
fix: Index store adds interface methods (#118)
1 parent 6426f3e commit 72bc93d

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

src/llama_index_cloud_sql_pg/async_index_store.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ async def aadd_index_struct(self, index_struct: IndexStruct) -> None:
150150
query = insert_query + values_statement + upsert_statement
151151
await self.__aexecute_query(query, index_row)
152152

153+
async def async_index_structs(self) -> list[IndexStruct]:
154+
"""Get all index structs.
155+
Returns:
156+
list[IndexStruct]: index structs
157+
"""
158+
return await self.aindex_structs()
159+
160+
async def async_add_index_struct(self, index_struct: IndexStruct) -> None:
161+
"""Add an index struct.
162+
Args:
163+
index_struct (IndexStruct): index struct
164+
"""
165+
await self.aadd_index_struct(index_struct)
166+
153167
async def adelete_index_struct(self, key: str) -> None:
154168
"""Delete an index struct.
155169

src/llama_index_cloud_sql_pg/index_store.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ def create_sync(
9696
index_store = engine._run_as_sync(coro)
9797
return cls(cls.__create_key, engine, index_store)
9898

99+
def add_index_struct(self, index_struct: IndexStruct) -> None:
100+
"""Add an index struct.
101+
102+
Args:
103+
index_struct (IndexStruct): index struct
104+
105+
"""
106+
return self._engine._run_as_sync(
107+
self.__index_store.aadd_index_struct(index_struct)
108+
)
109+
99110
async def aindex_structs(self) -> list[IndexStruct]:
100111
"""Get all index structs.
101112
@@ -125,16 +136,19 @@ async def aadd_index_struct(self, index_struct: IndexStruct) -> None:
125136
self.__index_store.aadd_index_struct(index_struct)
126137
)
127138

128-
def add_index_struct(self, index_struct: IndexStruct) -> None:
129-
"""Add an index struct.
139+
async def async_index_structs(self) -> list[IndexStruct]:
140+
"""Get all index structs.
141+
Returns:
142+
list[IndexStruct]: index structs
143+
"""
144+
return await self.aindex_structs()
130145

146+
async def async_add_index_struct(self, index_struct: IndexStruct) -> None:
147+
"""Add an index struct.
131148
Args:
132149
index_struct (IndexStruct): index struct
133-
134150
"""
135-
return self._engine._run_as_sync(
136-
self.__index_store.aadd_index_struct(index_struct)
137-
)
151+
await self.aadd_index_struct(index_struct)
138152

139153
async def adelete_index_struct(self, key: str) -> None:
140154
"""Delete an index struct.

tests/test_async_index_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def test_aindex_structs(self, index_store):
147147
index_graph_struct = IndexGraph()
148148

149149
await index_store.aadd_index_struct(index_dict_struct)
150-
await index_store.aadd_index_struct(index_graph_struct)
150+
await index_store.async_add_index_struct(index_graph_struct)
151151
await index_store.aadd_index_struct(index_list_struct)
152152

153153
indexes = await index_store.aindex_structs()

tests/test_index_store.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ async def test_aindex_structs(self, index_store):
149149
index_graph_struct = IndexGraph()
150150

151151
await index_store.aadd_index_struct(index_dict_struct)
152-
await index_store.aadd_index_struct(index_graph_struct)
152+
await index_store.async_add_index_struct(index_graph_struct)
153153
await index_store.aadd_index_struct(index_list_struct)
154154

155155
indexes = await index_store.aindex_structs()
156+
indexes_with_async = await index_store.async_index_structs()
156157

157-
index_store.add_index_struct(index_dict_struct)
158-
index_store.add_index_struct(index_graph_struct)
159-
index_store.add_index_struct(index_list_struct)
158+
assert indexes == indexes_with_async
159+
assert index_dict_struct in indexes
160+
assert index_list_struct in indexes
161+
assert index_graph_struct in indexes
160162

161163
async def test_warning(self, index_store):
162164
index_dict_struct = IndexDict()
@@ -270,9 +272,9 @@ async def test_aindex_structs(self, index_store):
270272

271273
indexes = index_store.index_structs()
272274

273-
index_store.add_index_struct(index_dict_struct)
274-
index_store.add_index_struct(index_graph_struct)
275-
index_store.add_index_struct(index_list_struct)
275+
assert index_dict_struct in indexes
276+
assert index_list_struct in indexes
277+
assert index_graph_struct in indexes
276278

277279
async def test_warning(self, index_store):
278280
index_dict_struct = IndexDict()

0 commit comments

Comments
 (0)