Skip to content

Commit

Permalink
feat!: Use collection names in the API (#89)
Browse files Browse the repository at this point in the history
* Use a string-typed ID for collections, and eliminate the "name" field

Working with collections is difficult. Most API endpoints currently
expect an integer identifier, which the user must find by making an API
query.

The point of collections is to provide logical separation between
documents, so it's more natural use use descriptive names to identify
the collection, ie "cooking-docs" or "prod-env".

This change makes the ID string-typed and user-provided, and drops the
"name" field which is now redundant. This is a breaking change - the SQL
schema is affected as well as the API types. In theory the "name" field
could be promoted to be a new idnetifier through a SQL migration (since
it has a unique constraint), but this seems like overkill at this stage.

* change queries to join for collection name

* update client and tests

* ruff

* comments

* add tests for documents, collections, chunks

* ruff

* ruff

---------

Co-authored-by: Ryan Michael <kerinin@gmail.com>
  • Loading branch information
bjchambers and kerinin authored Feb 14, 2024
1 parent d130875 commit 0c99005
Show file tree
Hide file tree
Showing 22 changed files with 543 additions and 351 deletions.
28 changes: 14 additions & 14 deletions dewy-client/dewy_client/api/kb/get_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@


def _get_kwargs(
id: int,
name: str,
) -> Dict[str, Any]:
_kwargs: Dict[str, Any] = {
"method": "get",
"url": f"/api/collections/{id}",
"url": f"/api/collections/{name}",
}

return _kwargs
Expand Down Expand Up @@ -50,7 +50,7 @@ def _build_response(


def sync_detailed(
id: int,
name: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Response[Union[Collection, HTTPValidationError]]:
Expand All @@ -59,7 +59,7 @@ def sync_detailed(
Get a specific collection.
Args:
id (int): The collection ID.
name (str): The collection name.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -70,7 +70,7 @@ def sync_detailed(
"""

kwargs = _get_kwargs(
id=id,
name=name,
)

response = client.get_httpx_client().request(
Expand All @@ -81,7 +81,7 @@ def sync_detailed(


def sync(
id: int,
name: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[Union[Collection, HTTPValidationError]]:
Expand All @@ -90,7 +90,7 @@ def sync(
Get a specific collection.
Args:
id (int): The collection ID.
name (str): The collection name.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -101,13 +101,13 @@ def sync(
"""

return sync_detailed(
id=id,
name=name,
client=client,
).parsed


async def asyncio_detailed(
id: int,
name: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Response[Union[Collection, HTTPValidationError]]:
Expand All @@ -116,7 +116,7 @@ async def asyncio_detailed(
Get a specific collection.
Args:
id (int): The collection ID.
name (str): The collection name.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -127,7 +127,7 @@ async def asyncio_detailed(
"""

kwargs = _get_kwargs(
id=id,
name=name,
)

response = await client.get_async_httpx_client().request(**kwargs)
Expand All @@ -136,7 +136,7 @@ async def asyncio_detailed(


async def asyncio(
id: int,
name: str,
*,
client: Union[AuthenticatedClient, Client],
) -> Optional[Union[Collection, HTTPValidationError]]:
Expand All @@ -145,7 +145,7 @@ async def asyncio(
Get a specific collection.
Args:
id (int): The collection ID.
name (str): The collection name.
Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
Expand All @@ -157,7 +157,7 @@ async def asyncio(

return (
await asyncio_detailed(
id=id,
name=name,
client=client,
)
).parsed
36 changes: 18 additions & 18 deletions dewy-client/dewy_client/api/kb/list_chunks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@

def _get_kwargs(
*,
collection_id: Union[None, Unset, int] = UNSET,
collection: Union[None, Unset, str] = UNSET,
document_id: Union[None, Unset, int] = UNSET,
page: Union[None, Unset, int] = 0,
per_page: Union[None, Unset, int] = 10,
) -> Dict[str, Any]:
params: Dict[str, Any] = {}

json_collection_id: Union[None, Unset, int]
if isinstance(collection_id, Unset):
json_collection_id = UNSET
json_collection: Union[None, Unset, str]
if isinstance(collection, Unset):
json_collection = UNSET
else:
json_collection_id = collection_id
params["collection_id"] = json_collection_id
json_collection = collection
params["collection"] = json_collection

json_document_id: Union[None, Unset, int]
if isinstance(document_id, Unset):
Expand Down Expand Up @@ -111,7 +111,7 @@ def _build_response(
def sync_detailed(
*,
client: Union[AuthenticatedClient, Client],
collection_id: Union[None, Unset, int] = UNSET,
collection: Union[None, Unset, str] = UNSET,
document_id: Union[None, Unset, int] = UNSET,
page: Union[None, Unset, int] = 0,
per_page: Union[None, Unset, int] = 10,
Expand All @@ -121,7 +121,7 @@ def sync_detailed(
List chunks.
Args:
collection_id (Union[None, Unset, int]): Limit to chunks associated with this collection
collection (Union[None, Unset, str]): Limit to chunks associated with this collection
document_id (Union[None, Unset, int]): Limit to chunks associated with this document
page (Union[None, Unset, int]): Default: 0.
per_page (Union[None, Unset, int]): Default: 10.
Expand All @@ -135,7 +135,7 @@ def sync_detailed(
"""

kwargs = _get_kwargs(
collection_id=collection_id,
collection=collection,
document_id=document_id,
page=page,
per_page=per_page,
Expand All @@ -151,7 +151,7 @@ def sync_detailed(
def sync(
*,
client: Union[AuthenticatedClient, Client],
collection_id: Union[None, Unset, int] = UNSET,
collection: Union[None, Unset, str] = UNSET,
document_id: Union[None, Unset, int] = UNSET,
page: Union[None, Unset, int] = 0,
per_page: Union[None, Unset, int] = 10,
Expand All @@ -161,7 +161,7 @@ def sync(
List chunks.
Args:
collection_id (Union[None, Unset, int]): Limit to chunks associated with this collection
collection (Union[None, Unset, str]): Limit to chunks associated with this collection
document_id (Union[None, Unset, int]): Limit to chunks associated with this document
page (Union[None, Unset, int]): Default: 0.
per_page (Union[None, Unset, int]): Default: 10.
Expand All @@ -176,7 +176,7 @@ def sync(

return sync_detailed(
client=client,
collection_id=collection_id,
collection=collection,
document_id=document_id,
page=page,
per_page=per_page,
Expand All @@ -186,7 +186,7 @@ def sync(
async def asyncio_detailed(
*,
client: Union[AuthenticatedClient, Client],
collection_id: Union[None, Unset, int] = UNSET,
collection: Union[None, Unset, str] = UNSET,
document_id: Union[None, Unset, int] = UNSET,
page: Union[None, Unset, int] = 0,
per_page: Union[None, Unset, int] = 10,
Expand All @@ -196,7 +196,7 @@ async def asyncio_detailed(
List chunks.
Args:
collection_id (Union[None, Unset, int]): Limit to chunks associated with this collection
collection (Union[None, Unset, str]): Limit to chunks associated with this collection
document_id (Union[None, Unset, int]): Limit to chunks associated with this document
page (Union[None, Unset, int]): Default: 0.
per_page (Union[None, Unset, int]): Default: 10.
Expand All @@ -210,7 +210,7 @@ async def asyncio_detailed(
"""

kwargs = _get_kwargs(
collection_id=collection_id,
collection=collection,
document_id=document_id,
page=page,
per_page=per_page,
Expand All @@ -224,7 +224,7 @@ async def asyncio_detailed(
async def asyncio(
*,
client: Union[AuthenticatedClient, Client],
collection_id: Union[None, Unset, int] = UNSET,
collection: Union[None, Unset, str] = UNSET,
document_id: Union[None, Unset, int] = UNSET,
page: Union[None, Unset, int] = 0,
per_page: Union[None, Unset, int] = 10,
Expand All @@ -234,7 +234,7 @@ async def asyncio(
List chunks.
Args:
collection_id (Union[None, Unset, int]): Limit to chunks associated with this collection
collection (Union[None, Unset, str]): Limit to chunks associated with this collection
document_id (Union[None, Unset, int]): Limit to chunks associated with this document
page (Union[None, Unset, int]): Default: 0.
per_page (Union[None, Unset, int]): Default: 10.
Expand All @@ -250,7 +250,7 @@ async def asyncio(
return (
await asyncio_detailed(
client=client,
collection_id=collection_id,
collection=collection,
document_id=document_id,
page=page,
per_page=per_page,
Expand Down
Loading

0 comments on commit 0c99005

Please sign in to comment.