Retrieve entities from the specified store.
(
self,
parent_id: UUID,
store_type: StoreType,
offset: int,
limit: int,
entity_ids: Optional[list[UUID]] = None,
entity_names: Optional[list[str]] = None,
include_embeddings: bool = False,
)
| 164 | ) |
| 165 | |
| 166 | async def get( |
| 167 | self, |
| 168 | parent_id: UUID, |
| 169 | store_type: StoreType, |
| 170 | offset: int, |
| 171 | limit: int, |
| 172 | entity_ids: Optional[list[UUID]] = None, |
| 173 | entity_names: Optional[list[str]] = None, |
| 174 | include_embeddings: bool = False, |
| 175 | ): |
| 176 | """Retrieve entities from the specified store.""" |
| 177 | table_name = self._get_entity_table_for_store(store_type) |
| 178 | |
| 179 | conditions = ["parent_id = $1"] |
| 180 | params: list[Any] = [parent_id] |
| 181 | param_index = 2 |
| 182 | |
| 183 | if entity_ids: |
| 184 | conditions.append(f"id = ANY(${param_index})") |
| 185 | params.append(entity_ids) |
| 186 | param_index += 1 |
| 187 | |
| 188 | if entity_names: |
| 189 | conditions.append(f"name = ANY(${param_index})") |
| 190 | params.append(entity_names) |
| 191 | param_index += 1 |
| 192 | |
| 193 | select_fields = """ |
| 194 | id, name, category, description, parent_id, |
| 195 | chunk_ids, metadata |
| 196 | """ |
| 197 | if include_embeddings: |
| 198 | select_fields += ", description_embedding" |
| 199 | |
| 200 | COUNT_QUERY = f""" |
| 201 | SELECT COUNT(*) |
| 202 | FROM {self._get_table_name(table_name)} |
| 203 | WHERE {" AND ".join(conditions)} |
| 204 | """ |
| 205 | |
| 206 | count_params = params[: param_index - 1] |
| 207 | count = ( |
| 208 | await self.connection_manager.fetch_query( |
| 209 | COUNT_QUERY, count_params |
| 210 | ) |
| 211 | )[0]["count"] |
| 212 | |
| 213 | QUERY = f""" |
| 214 | SELECT {select_fields} |
| 215 | FROM {self._get_table_name(table_name)} |
| 216 | WHERE {" AND ".join(conditions)} |
| 217 | ORDER BY created_at |
| 218 | OFFSET ${param_index} |
| 219 | """ |
| 220 | params.append(offset) |
| 221 | param_index += 1 |
| 222 | |
| 223 | if limit != -1: |
nothing calls this directly
no test coverage detected