Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 10
Collections: Add dynamic batching#718
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
614801cf8f9c2ff9b3365a074e361106abcff0726fc7da9f08437442f94998fed1ee385ec17be3246e88292be604c20ac99be2e06b02b8f2db593e2c775c90f809ce8651f0385e25928aa19cd569f5c008acde0ba098f15a4087c8c65616aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """add columns to collection job and documents table | ||
| Revision ID: 053 | ||
| Revises: 052 | ||
| Create Date: 2026-03-25 10:09:47.318575 | ||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| # revision identifiers, used by Alembic. | ||
| revision = "053" | ||
| down_revision = "052" | ||
| branch_labels = None | ||
| depends_on = None | ||
| def upgrade(): | ||
| op.add_column( | ||
| "collection_jobs", | ||
| sa.Column( | ||
| "docs_num", | ||
| sa.Integer(), | ||
| nullable=True, | ||
| comment="Total number of documents to be processed in this job", | ||
| ), | ||
| ) | ||
| op.add_column( | ||
| "collection_jobs", | ||
| sa.Column( | ||
| "total_size_mb", | ||
| sa.Float(), | ||
| nullable=True, | ||
| comment="Total size of documents being uploaded to collection in MB", | ||
| ), | ||
| ) | ||
| op.add_column( | ||
| "collection_jobs", | ||
| sa.Column( | ||
| "documents", | ||
| sa.JSON(), | ||
| nullable=True, | ||
| comment="List of documents given to make collection", | ||
| ), | ||
| ) | ||
| op.add_column( | ||
| "document", | ||
| sa.Column( | ||
| "file_size_kb", | ||
| sa.Float(), | ||
| nullable=True, | ||
| comment="Size of the document in kilobytes (KB)", | ||
| ), | ||
| ) | ||
| def downgrade(): | ||
| op.drop_column("document", "file_size_kb") | ||
| op.drop_column("collection_jobs", "total_size_mb") | ||
| op.drop_column("collection_jobs", "docs_num") | ||
| op.drop_column("collection_jobs", "documents") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import json | ||
| import logging | ||
| import functools as ft | ||
| from io import BytesIO | ||
| from typing import Iterable | ||
| from openai import OpenAI, OpenAIError | ||
| from pydantic import BaseModel | ||
| from app.core.cloud import CloudStorage | ||
| from app.core.config import settings | ||
| from app.models import Document | ||
| logger = logging.getLogger(__name__) | ||
| @@ -121,15 +121,13 @@ def update( | ||
| storage: CloudStorage, | ||
| documents: Iterable[Document], | ||
| ): | ||
| files = [] | ||
| for docs in documents: | ||
| files = [] | ||
| for d in docs: | ||
| f_obj = storage.stream(d.object_store_url) | ||
| # monkey patch botocore.response.StreamingBody to make | ||
| # OpenAI happy | ||
| # Get file bytes and wrap in BytesIO for OpenAI API | ||
| content = storage.get(d.object_store_url) | ||
| f_obj = BytesIO(content) | ||
| f_obj.name = d.fname | ||
| files.append(f_obj) | ||
| logger.info( | ||
| @@ -143,31 +141,11 @@ def update( | ||
| f"[OpenAIVectorStoreCrud.update] File upload completed | {{'vector_store_id': '{vector_store_id}', 'completed_files': {req.file_counts.completed}, 'total_files': {req.file_counts.total}}}" | ||
| ) | ||
| if req.file_counts.completed != req.file_counts.total: | ||
| view = {x.fname: x for x in docs} | ||
| for i in self.read(vector_store_id): | ||
| if i.last_error is None: | ||
| fname = self.client.files.retrieve(i.id) | ||
| view.pop(fname) | ||
| error = { | ||
| "error": "OpenAI document processing error", | ||
| "documents": list(view.values()), | ||
| } | ||
| try: | ||
| raise InterruptedError(json.dumps(error, cls=BaseModelEncoder)) | ||
| except InterruptedError as err: | ||
| logger.error( | ||
| f"[OpenAIVectorStoreCrud.update] Document processing error | {{'vector_store_id': '{vector_store_id}', 'error': '{error['error']}', 'failed_documents': {len(error['documents'])}}}", | ||
| exc_info=True, | ||
| ) | ||
| raise | ||
| while files: | ||
| f_obj = files.pop() | ||
| f_obj.close() | ||
| logger.info( | ||
| f"[OpenAIVectorStoreCrud.update] Closed file stream | {{'vector_store_id': '{vector_store_id}', 'filename': '{f_obj.name}'}}" | ||
| error_msg = f"OpenAI document processing error: {req.file_counts.completed}/{req.file_counts.total} files completed" | ||
| logger.error( | ||
| f"[OpenAIVectorStoreCrud.update] Document processing error | {{'vector_store_id': '{vector_store_id}', 'completed_files': {req.file_counts.completed}, 'total_files': {req.file_counts.total}}}" | ||
| ) | ||
| raise InterruptedError(error_msg) | ||
nishika26 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| yield from docs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,7 +2,8 @@ | ||
| from enum import Enum | ||
| from uuid import UUID, uuid4 | ||
| from sqlmodel import Column, Field, SQLModel, Text | ||
| from pydantic import field_validator | ||
| from sqlmodel import JSON, Column, Field, SQLModel, Text | ||
| from app.core.util import now | ||
| from app.models.collection import CollectionIDPublic, CollectionPublic | ||
| @@ -53,12 +54,32 @@ class CollectionJob(SQLModel, table=True): | ||
| description="Tracing ID for correlating logs and traces.", | ||
| sa_column_kwargs={"comment": "Tracing ID for correlating logs and traces"}, | ||
| ) | ||
| docs_num: int | None = Field( | ||
| default=None, | ||
| description="Total number of documents to be processed in this job", | ||
| sa_column_kwargs={ | ||
| "comment": "Total number of documents to be processed in this job" | ||
| }, | ||
| ) | ||
| total_size_mb: float | None = Field( | ||
| default=None, | ||
| description="Total size of documents being uploaded to collection in MB", | ||
| sa_column_kwargs={ | ||
| "comment": "Total size of documents being uploaded to collection in MB" | ||
| }, | ||
| ) | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| error_message: str | None = Field( | ||
| default=None, | ||
| sa_column=Column( | ||
| Text, nullable=True, comment="Error message if the job failed" | ||
| ), | ||
| ) | ||
| documents: list[str] | None = Field( | ||
| default=None, | ||
| sa_column=Column( | ||
| JSON, nullable=True, comment="List of documents given to make collection" | ||
| ), | ||
| ) | ||
| # Foreign keys | ||
| collection_id: UUID | None = Field( | ||
| @@ -106,14 +127,17 @@ class CollectionJobCreate(SQLModel): | ||
| collection_id: UUID | None = None | ||
| status: CollectionJobStatus | ||
| action_type: CollectionActionType | ||
| docs_num: int | None = None | ||
| project_id: int | ||
| documents: list[str] | None = None | ||
| class CollectionJobUpdate(SQLModel): | ||
| task_id: str | None = None | ||
| status: CollectionJobStatus | None = None | ||
| error_message: str | None = None | ||
| collection_id: UUID | None = None | ||
| total_size_mb: float | None = None | ||
| trace_id: str | None = None | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.