Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agents-api): Add embeddings to doc get/list response #578

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions agents-api/agents_api/autogen/Docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ class Doc(BaseModel):
"""
Contents of the document
"""
embeddings: Annotated[
list[float] | list[list[float]] | None,
Field(None, json_schema_extra={"readOnly": True}),
]
"""
Embeddings for the document
"""


class DocOwner(BaseModel):
Expand Down
4 changes: 3 additions & 1 deletion agents-api/agents_api/models/docs/get_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
one=True,
transform=lambda d: {
"content": [s[1] for s in sorted(d["snippet_data"], key=lambda x: x[0])],
"embeddings": [s[2] for s in sorted(d["snippet_data"], key=lambda x: x[0])],
**d,
},
)
Expand Down Expand Up @@ -68,8 +69,9 @@ def get_doc(
doc_id,
index,
content,
embedding,
},
snippet_data = [index, content]
snippet_data = [index, content, embedding]

?[
id,
Expand Down
4 changes: 3 additions & 1 deletion agents-api/agents_api/models/docs/list_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
Doc,
transform=lambda d: {
"content": [s[1] for s in sorted(d["snippet_data"], key=lambda x: x[0])],
"embeddings": [s[2] for s in sorted(d["snippet_data"], key=lambda x: x[0])],
**d,
},
)
Expand Down Expand Up @@ -67,8 +68,9 @@ def list_docs(
doc_id: id,
index,
content,
embedding,
}},
snippet_data = [index, content]
snippet_data = [index, content, embedding]

?[
owner_type,
Expand Down
Binary file added cozo.db
Binary file not shown.
4 changes: 4 additions & 0 deletions typespec/docs/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ model Doc {

/** Contents of the document */
content: string | string[];

/** Embeddings for the document */
@visibility("read")
embeddings?: float32[] | float32[][];
}

/** Payload for creating a doc */
Expand Down
Loading