Skip to content

Commit

Permalink
feat(agents-api): Performance improvements (#749)
Browse files Browse the repository at this point in the history
- **feat(agents-api,typespec): Limit max_k for search to 50; max items
for embed to 100**
- **refactor(typespec): Remove older 0.4.0 version of typespec**
- **feat: Add metadata filter argument to doc search**
- **feat(agents-api): Performance improvements - use KNN unless dataset
too big**
- **feat(agents-api): Performance improvements - merge metadata_filter**

<!-- ELLIPSIS_HIDDEN -->

----

> [!IMPORTANT]
> This PR improves agents API performance by limiting search and embed
parameters, adding metadata filtering, updating typespec versions, and
optimizing search functions.
> 
>   - **Behavior**:
> - Limit `max_k` for search to 50 and max items for embed to 100 in
`Docs.py`.
> - Add `metadata_filter` argument to document search functions in
`search_docs_by_embedding.py`, `search_docs_by_text.py`, and
`search_docs_hybrid.py`.
> - Use KNN for search unless dataset exceeds `ann_threshold` in
`search_docs_by_embedding.py`.
>   - **Refactor**:
>     - Remove older `0.4.0` version of typespec.
>     - Update `openapi.yaml` to `1.0.0` version.
>   - **Models**:
> - Split `EmbedQueryRequest` into `SingleEmbedQueryRequest` and
`MultipleEmbedQueryRequest` in `Docs.py` and `models.tsp`.
>   - **Misc**:
>     - Adjust `workers` and add `timeout` in `gunicorn_conf.py`.
>     - Update `docker-compose.yml` to sync `gunicorn_conf.py`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=julep-ai%2Fjulep&utm_source=github&utm_medium=referral)<sup>
for c0bd25c. It will automatically
update as commits are pushed.</sup>

<!-- ELLIPSIS_HIDDEN -->

---------

Signed-off-by: Diwank Singh Tomer <[email protected]>
Co-authored-by: Dmitry Paramonov <[email protected]>
  • Loading branch information
creatorrr and whiterabbit1983 authored Oct 26, 2024
1 parent 65e912d commit bb6b238
Show file tree
Hide file tree
Showing 24 changed files with 357 additions and 6,390 deletions.
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Chat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
49 changes: 32 additions & 17 deletions agents-api/agents_api/autogen/Docs.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

from typing import Annotated, Any, Literal
from uuid import UUID

from pydantic import AwareDatetime, BaseModel, ConfigDict, Field
from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, StrictBool


class BaseDocSearchRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
limit: Annotated[int, Field(10, ge=1, le=100)]
limit: Annotated[int, Field(10, ge=1, le=50)]
lang: Literal["en-US"] = "en-US"
"""
The language to be used for text-only search. Support for other languages coming soon.
"""
metadata_filter: dict[str, float | str | StrictBool | None] = {}


class CreateDocRequest(BaseModel):
Expand Down Expand Up @@ -109,20 +110,6 @@ class DocSearchResponse(BaseModel):
"""


class EmbedQueryRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
text: str | list[str]
"""
Text or texts to embed
"""
embed_instruction: str = ""
"""
Instruction for the embedding model.
"""


class EmbedQueryResponse(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
Expand Down Expand Up @@ -155,6 +142,34 @@ class HybridDocSearchRequest(BaseDocSearchRequest):
"""


class MultipleEmbedQueryRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
text: Annotated[list[str], Field(max_length=100, min_length=1)]
"""
Texts to embed
"""
embed_instruction: str = ""
"""
Instruction for the embedding model.
"""


class SingleEmbedQueryRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
text: str
"""
Text to embed
"""
embed_instruction: str = ""
"""
Instruction for the embedding model.
"""


class Snippet(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Entries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Executions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Jobs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Sessions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/Users.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion agents-api/agents_api/autogen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# generated by datamodel-codegen:
# filename: openapi-0.4.0.yaml
# filename: openapi-1.0.0.yaml
Loading

0 comments on commit bb6b238

Please sign in to comment.