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(api): adds migration for tracking vector store indexing status #830

Merged
merged 116 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
1fead30
Adds migration for tracking vector store indexing status
CollectiveUnicorn Jul 24, 2024
8504585
Removes enforcement of status
CollectiveUnicorn Jul 24, 2024
7c87604
Simplifies sql query to focus on vector_store_file
CollectiveUnicorn Jul 24, 2024
0f4125a
Pulls supabase-realtime image from official instead of bitnami
CollectiveUnicorn Jul 25, 2024
53e44a5
Reverts supabase realtime image replacement
CollectiveUnicorn Jul 25, 2024
f652a16
Adds separate supabase realtime config for websocket/api
CollectiveUnicorn Aug 2, 2024
4b3fd69
Updates the default config with necessary vars
CollectiveUnicorn Aug 2, 2024
f6d4166
Adds init container placeholder for seeding tables via curl
CollectiveUnicorn Aug 2, 2024
775339b
Moves configmap changes to extra configs
CollectiveUnicorn Aug 2, 2024
e6d5394
Renames variable for compatbility with supabase version
CollectiveUnicorn Aug 2, 2024
427ffce
Ensures configmap is mounted in container
CollectiveUnicorn Aug 2, 2024
7ba8566
Specify the variables manuallY
CollectiveUnicorn Aug 2, 2024
62a2793
Fixes env var typo
CollectiveUnicorn Aug 2, 2024
86f0b4b
Adds script to seed the realtime instance
CollectiveUnicorn Aug 2, 2024
4d9bbd9
Moves script somewhere with permissions
CollectiveUnicorn Aug 2, 2024
39cc4d5
Moves script to values file
CollectiveUnicorn Aug 2, 2024
dca8c65
Updates url and var for realtime init container
CollectiveUnicorn Aug 2, 2024
c254ee3
Replace initContainer with sidecars
CollectiveUnicorn Aug 2, 2024
811cefb
Adds wait for realtime container
CollectiveUnicorn Aug 2, 2024
1ec9ad8
Replaces os-shell with busybox
CollectiveUnicorn Aug 2, 2024
2829b41
Replaces busybox container with a curl container
CollectiveUnicorn Aug 2, 2024
4a30a4b
Replaces nc wait with curl wait
CollectiveUnicorn Aug 2, 2024
ffa7ffa
Try to replace how the realtimme seed is happening
CollectiveUnicorn Aug 5, 2024
a8fe333
Merge branch 'main' into fix-supabase-realtime
CollectiveUnicorn Aug 5, 2024
3677383
Replaces job with inline curl call
CollectiveUnicorn Aug 5, 2024
395454c
Replaces wget commands with curl
CollectiveUnicorn Aug 5, 2024
f99eda0
Replaces invalid health endpoint on realtime
CollectiveUnicorn Aug 5, 2024
0327095
Moves the curl command to one line
CollectiveUnicorn Aug 5, 2024
18fccac
Updates versions of supabase-realtime
CollectiveUnicorn Aug 5, 2024
5776532
Sets the ENC_KEY to a default value of 16 chars
CollectiveUnicorn Aug 5, 2024
294ec62
Makes the sidecar sleep after a successful run to prevent crashbackloops
CollectiveUnicorn Aug 5, 2024
b7cb54c
Adds notify private alpha
CollectiveUnicorn Aug 7, 2024
27b96e3
Replaces DB_ENC_KEY with JWT_SECRET
CollectiveUnicorn Aug 7, 2024
a2932a4
Updates the JWT_SECRET to be correct
CollectiveUnicorn Aug 7, 2024
cc85394
Removes unnecessary quotes that interfere with SSL configs
CollectiveUnicorn Aug 7, 2024
a33a3ba
Replaces sidecar based realtime tenant initialization with init args
CollectiveUnicorn Aug 8, 2024
3882e15
Adds back necessary quotes
CollectiveUnicorn Aug 8, 2024
5296c66
Adds migration to update the freshly seeded db
CollectiveUnicorn Aug 8, 2024
673c07a
Randomly generates enc_secret instead of hard coding it
CollectiveUnicorn Aug 8, 2024
537239e
Replaces secret name to prevent deployment errors
CollectiveUnicorn Aug 8, 2024
92c314f
Creates _realtime schema and sets up deployment to use it
CollectiveUnicorn Aug 8, 2024
5b055e5
Set the search path back to public
CollectiveUnicorn Aug 8, 2024
c04adf6
Initialize _realtime table in after connect query
CollectiveUnicorn Aug 8, 2024
87e8a52
Replaces multiple queries with a single query
CollectiveUnicorn Aug 8, 2024
a5cbb4b
Updates the migration to represent the new location
CollectiveUnicorn Aug 8, 2024
bcc000d
Swaps out postgres image for one with wal2json
CollectiveUnicorn Aug 8, 2024
3cc1bc1
Moves back to older postgres image
CollectiveUnicorn Aug 8, 2024
c57facf
Switch to official supabase postgres image
CollectiveUnicorn Aug 8, 2024
1c083e8
Returns to using a base postgres image
CollectiveUnicorn Aug 8, 2024
11888cb
Updates the config to set the wal_level to logical
CollectiveUnicorn Aug 8, 2024
ce97caf
Merge branch 'main' into fix-supabase-realtime
CollectiveUnicorn Aug 8, 2024
30b8ba2
Merge branch 'fix-supabase-realtime' into 788-featapi-vector-store-in…
CollectiveUnicorn Aug 9, 2024
79e09a2
Removes explicit install of requests dep and adds new realtime dep
CollectiveUnicorn Aug 13, 2024
f682926
Reverts removal of requests dependency in favor of doing it an a sepa…
CollectiveUnicorn Aug 13, 2024
6a713ad
Installs specific realtime version and switches how the tests listens…
CollectiveUnicorn Aug 13, 2024
351488a
Adds complete test to check whether realtime is working
CollectiveUnicorn Aug 14, 2024
d084c72
Ruff linting
CollectiveUnicorn Aug 14, 2024
3d57f6d
Adds fastapi to dev deps list
CollectiveUnicorn Aug 14, 2024
8532be5
Fixes linting issue
CollectiveUnicorn Aug 14, 2024
cfba262
Updates comments
CollectiveUnicorn Aug 14, 2024
33ef8fa
Adds missing dependency
CollectiveUnicorn Aug 14, 2024
49cf899
Merge branch 'main' into 788-featapi-vector-store-indexing-status
CollectiveUnicorn Aug 21, 2024
b1955cd
Pin supabase version at root to 2.6.0
CollectiveUnicorn Aug 22, 2024
568b4c9
Add background task for processing vectors
CollectiveUnicorn Aug 22, 2024
2d6c566
Create usable placeholder and refactor creation logic into indexing file
CollectiveUnicorn Aug 23, 2024
58e8193
Ruff linting
CollectiveUnicorn Aug 23, 2024
b1d91c4
Updates modify vector store to use background task when files are pro…
CollectiveUnicorn Aug 23, 2024
20dca4a
Ruff linting
CollectiveUnicorn Aug 23, 2024
e0c472a
Ruff linting
CollectiveUnicorn Aug 23, 2024
00e6e61
Removes hard dependency on FastAPI for indexing, cleans up comments
CollectiveUnicorn Aug 26, 2024
d8b949c
Adds initial test
CollectiveUnicorn Aug 26, 2024
bfb71ed
Removes unnecessary import
CollectiveUnicorn Aug 26, 2024
fd2a2c3
Ruff linting
CollectiveUnicorn Aug 26, 2024
32fa43e
Moves deletion test t o end of test_vector_stores
CollectiveUnicorn Aug 26, 2024
8e6e403
Updates content payload
CollectiveUnicorn Aug 26, 2024
a0d8044
Add messages client to test
CollectiveUnicorn Aug 26, 2024
ae554b2
Replaces more incorrect clients
CollectiveUnicorn Aug 26, 2024
f38f2cf
Switch from llama-cpp-python to test-chat
CollectiveUnicorn Aug 26, 2024
605a06c
Moves vector stores e2e test into test_api.py
CollectiveUnicorn Aug 26, 2024
8011c22
Reverts test_vector_stores.py to match main
CollectiveUnicorn Aug 26, 2024
c2b1c05
Makes test handle concurrency better, allow for re-using creds
CollectiveUnicorn Aug 27, 2024
fc38a8e
Updates text-embeddings to run on GPU
CollectiveUnicorn Aug 27, 2024
c5c580f
Updates text-embeddings to run on GPU
CollectiveUnicorn Aug 27, 2024
d949f74
Replaces gpu with cuda
CollectiveUnicorn Aug 27, 2024
03186f1
Removes code specifying the gpu device
CollectiveUnicorn Aug 27, 2024
44f5578
Bumps wait time up to 10 min
CollectiveUnicorn Aug 27, 2024
e7cbc2d
Reduces wait time down to 3 min and swaps out pdf
CollectiveUnicorn Aug 27, 2024
143933c
Adds fastapi to project root for test
CollectiveUnicorn Aug 27, 2024
42561ff
Merge branch 'main' into background-tasks
CollectiveUnicorn Aug 27, 2024
dbeadc6
Moves test into new e2e that has multiple backends
CollectiveUnicorn Aug 27, 2024
0324f02
Bumps migration name to latest
CollectiveUnicorn Aug 27, 2024
8bb0166
Fixes typo
CollectiveUnicorn Aug 27, 2024
d952c6a
Adds comment for service key
CollectiveUnicorn Aug 27, 2024
d6439bf
Merge branch 'main' into 788-featapi-vector-store-indexing-status
CollectiveUnicorn Aug 27, 2024
18dc5e7
Changes updated_at precision to ms
CollectiveUnicorn Aug 27, 2024
68a29c2
Bumps version to 0.11.1
CollectiveUnicorn Aug 28, 2024
517bb75
Resolves incorrect usage_bytes comment
CollectiveUnicorn Aug 28, 2024
17f1a3a
Reverts test back to match main
CollectiveUnicorn Aug 28, 2024
50fc526
Change how the timestamp is generated
CollectiveUnicorn Aug 28, 2024
1a60c9a
Lets the db set the created_at time for the test
CollectiveUnicorn Aug 28, 2024
5ad9563
Returns manual uuid creation
CollectiveUnicorn Aug 28, 2024
187d653
Merge branch 'main' into background-tasks
CollectiveUnicorn Aug 29, 2024
360fab1
Merge branch 'main' into 788-featapi-vector-store-indexing-status
CollectiveUnicorn Aug 29, 2024
a1adcfd
Merge branch 'background-tasks' into 788-featapi-vector-store-indexin…
CollectiveUnicorn Aug 29, 2024
059ab1a
Updates ids to be blank and allow db to generate
CollectiveUnicorn Aug 31, 2024
9df884d
Merge branch 'main' into background-tasks
CollectiveUnicorn Aug 31, 2024
9f6ece2
Switch to test fixture for openai client
CollectiveUnicorn Aug 31, 2024
928e0f0
Merge branch 'background-tasks' into 788-featapi-vector-store-indexin…
CollectiveUnicorn Sep 3, 2024
f08bd38
Merge branch 'main' into background-tasks
CollectiveUnicorn Sep 3, 2024
ebb2ed2
Adds logging and cleanup operations for failed indexing
CollectiveUnicorn Sep 3, 2024
53d3b2f
Merge branch 'background-tasks' into 788-featapi-vector-store-indexin…
CollectiveUnicorn Sep 3, 2024
7eea9d8
Fixes typo
CollectiveUnicorn Sep 3, 2024
4f1dbcd
Merge branch 'main' into 788-featapi-vector-store-indexing-status
CollectiveUnicorn Sep 3, 2024
8dee0ad
Merge branch 'main' into 788-featapi-vector-store-indexing-status
CollectiveUnicorn Sep 4, 2024
ddc6cce
Merge branch 'main' into 788-featapi-vector-store-indexing-status
gphorvath Sep 4, 2024
b30efd8
Trigger Build
CollectiveUnicorn Sep 4, 2024
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
1 change: 1 addition & 0 deletions .github/actions/lfai-core/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ runs:
id: set-env-var
run: |
echo "ANON_KEY=$(uds zarf tools kubectl get secret supabase-bootstrap-jwt -n leapfrogai -o jsonpath='{.data.anon-key}' | base64 -d)" >> "$GITHUB_ENV"
echo "SERVICE_KEY=$(uds zarf tools kubectl get secret supabase-bootstrap-jwt -n leapfrogai -o jsonpath='{.data.service-key}' | base64 -d)" >> "$GITHUB_ENV"

- name: Deploy LFAI-API
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-playwright.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# End-to-end testing that deploys and tests Supabase, API, UI, and VLLM
# End-to-end testing that deploys and tests Supabase, API, and UI

name: e2e-playwright
on:
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/e2e-text-backend-full-cpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# End-to-end testing that deploys and tests Supabase, API, llama-cpp-python, and text-embeddings

name: e2e-text-backend-full-cpu
on:
pull_request:
types:
- opened # default trigger
- reopened # default trigger
- synchronize # default trigger
- ready_for_review # don't run on draft PRs
- milestoned # allows us to trigger on bot PRs
paths:
# Catch-all
- "**"

# Ignore updates to the .github directory, unless it's this current file
- "!.github/**"
- ".github/workflows/e2e-text-backend-full-cpu.yaml"
- ".github/actions/uds-cluster/action.yaml"

# Ignore docs and website things
- "!**.md"
- "!docs/**"
- "!adr/**"
- "!website/**"
- "!netlify.toml"

# Ignore updates to generic github metadata files
- "!CODEOWNERS"
- "!.gitignore"
- "!LICENSE"

# Ignore local development files
- "!.pre-commit-config.yaml"

# Ignore non e2e tests changes
- "!tests/pytest/**"

# Ignore LFAI-UI source code changes
- "!src/leapfrogai_ui/**"

# Ignore changes to unrelated packages
- "!packages/k3d-gpu/**"
- "!packages/repeater/**"
- "!packages/ui/**"
- "!packages/vllm/**"
- "!packages/whisper/**"



concurrency:
group: e2e-text-backend-full-cpu-${{ github.ref }}
cancel-in-progress: true

jobs:
e2e_text_backend_full_cpu:
runs-on: ai-ubuntu-big-boy-8-core
if: ${{ !github.event.pull_request.draft }}

steps:
- name: Checkout Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Python
uses: ./.github/actions/python

- name: Setup UDS Cluster
uses: ./.github/actions/uds-cluster
with:
registry1Username: ${{ secrets.IRON_BANK_ROBOT_USERNAME }}
registry1Password: ${{ secrets.IRON_BANK_ROBOT_PASSWORD }}

- name: Setup LFAI-API and Supabase
uses: ./.github/actions/lfai-core

##########
# text-embeddings
##########
- name: Deploy text-embeddings
run: |
make build-text-embeddings LOCAL_VERSION=e2e-test
docker image prune -af
uds zarf package deploy packages/text-embeddings/zarf-package-text-embeddings-amd64-e2e-test.tar.zst -l=trace --confirm
rm packages/text-embeddings/zarf-package-text-embeddings-amd64-e2e-test.tar.zst

##########
# llama
##########
- name: Deploy llama-cpp-python
run: |
make build-llama-cpp-python LOCAL_VERSION=e2e-test
docker image prune -af
uds zarf package deploy packages/llama-cpp-python/zarf-package-llama-cpp-python-amd64-e2e-test.tar.zst -l=trace --confirm
rm packages/llama-cpp-python/zarf-package-llama-cpp-python-amd64-e2e-test.tar.zst

##########
# Test
##########
- name: Test Text Backend
run: |
python -m pytest ./tests/e2e/test_text_backend_full.py -v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Update the vector_store_file table to add an updated_at column
ALTER TABLE vector_store_file ADD COLUMN updated_at timestamp DEFAULT timezone('utc', now()) NOT NULL;

-- Add an index on user_id for faster queries
CREATE INDEX idx_vector_store_file_user_id ON vector_store_file(user_id);

-- Create a function to update the updated_at column
CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = timezone('utc', now());
RETURN NEW;
END;
$$ language 'plpgsql';

-- Create a trigger to automatically update the updated_at column
CREATE TRIGGER update_vector_store_file_modtime
BEFORE UPDATE ON vector_store_file
FOR EACH ROW
EXECUTE FUNCTION update_modified_column();

-- Enable Supabase realtime for the vector_store_file table
alter publication supabase_realtime
add table vector_store_file;
5 changes: 4 additions & 1 deletion packages/text-embeddings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

class InstructorEmbedding:
async def CreateEmbedding(self, request: EmbeddingRequest, context: GrpcContext):
embeddings = model.encode(request.inputs)
# Run the CPU-intensive encoding in a separate thread
embeddings = await asyncio.to_thread(
model.encode, sentences=request.inputs, show_progress_bar=True
)

embeddings = [Embedding(embedding=inner_list) for inner_list in embeddings]
return EmbeddingResponse(embeddings=embeddings)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dev = [
"requests-toolbelt",
"pytest",
"huggingface_hub[cli,hf_transfer]",
"fastapi",
"supabase == 2.6.0"
gphorvath marked this conversation as resolved.
Show resolved Hide resolved
]

dev-whisper = ["ctranslate2 == 4.1.0", "transformers[torch] == 4.39.3"]
Expand Down
155 changes: 104 additions & 51 deletions src/leapfrogai_api/backend/rag/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import tempfile
import time
from fastapi import HTTPException, UploadFile, status
from fastapi import HTTPException, UploadFile, status, BackgroundTasks
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from openai.types.beta.vector_store import FileCounts, VectorStore
Expand Down Expand Up @@ -89,7 +89,7 @@ async def index_file(self, vector_store_id: str, file_id: str) -> VectorStoreFil
),
object="vector_store.file",
status=VectorStoreFileStatus.FAILED.value,
usage_bytes=0,
usage_bytes=0, # Leave blank to have Postgres calculate the document bytes
vector_store_id=vector_store_id,
)
return await crud_vector_store_file.create(object_=vector_store_file)
Expand All @@ -100,7 +100,7 @@ async def index_file(self, vector_store_id: str, file_id: str) -> VectorStoreFil
last_error=None,
object="vector_store.file",
status=VectorStoreFileStatus.IN_PROGRESS.value,
usage_bytes=0,
usage_bytes=0, # Leave blank to have Postgres calculate the document bytes
vector_store_id=vector_store_id,
)

Expand Down Expand Up @@ -154,59 +154,90 @@ async def index_files(
return responses

async def create_new_vector_store(
self, request: CreateVectorStoreRequest
self,
request: CreateVectorStoreRequest,
background_tasks: BackgroundTasks | None = None,
) -> VectorStore:
"""Create a new vector store given a set of file ids"""
crud_vector_store = CRUDVectorStore(db=self.db)

last_active_at = int(time.time())

expires_after, expires_at = request.get_expiry(last_active_at)
current_time = int(time.time())
expires_after, expires_at = request.get_expiry(current_time)

try:
vector_store = VectorStore(
# Create a placeholder vector store
placeholder_vector_store = VectorStore(
id="", # Leave blank to have Postgres generate a UUID
usage_bytes=0, # Automatically calculated by DB
name=request.name or "",
status=VectorStoreStatus.IN_PROGRESS.value,
object="vector_store",
created_at=0, # Leave blank to have Postgres generate a timestamp
last_active_at=current_time,
file_counts=FileCounts(
cancelled=0, completed=0, failed=0, in_progress=0, total=0
),
last_active_at=last_active_at, # Set to current time
usage_bytes=0, # Leave blank to have Postgres calculate the document bytes
metadata=request.metadata,
name=request.name or "",
object="vector_store",
status=VectorStoreStatus.IN_PROGRESS.value,
expires_after=expires_after,
expires_at=expires_at,
)
new_vector_store = await crud_vector_store.create(object_=vector_store)

if request.file_ids != []:
responses = await self.index_files(
new_vector_store.id, request.file_ids
)
# Save the placeholder to the database
saved_placeholder = await crud_vector_store.create(
object_=placeholder_vector_store
)

for response in responses:
await self._increment_vector_store_file_status(
new_vector_store, response
)
if saved_placeholder is None:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Unable to create vector store",
)

new_vector_store.status = VectorStoreStatus.COMPLETED.value
# Split the files, convert the chunks into vectors, and insert them into the db
if background_tasks:
# Perform the indexing in the background
background_tasks.add_task(
self._complete_vector_store_creation,
saved_placeholder.id,
request,
)
else:
await self._complete_vector_store_creation(
saved_placeholder.id, request
)

return await crud_vector_store.update(
id_=new_vector_store.id,
object_=new_vector_store,
)
return saved_placeholder
except Exception as exc:
logging.error(exc)
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Unable to parse vector store request",
) from exc

async def _complete_vector_store_creation(
self, vector_store_id: str, request: CreateVectorStoreRequest
):
"""Complete the vector store creation process in the background."""
crud_vector_store = CRUDVectorStore(db=self.db)
vector_store = await crud_vector_store.get(
filters=FilterVectorStore(id=vector_store_id)
)

if request.file_ids != []:
responses = await self.index_files(vector_store_id, request.file_ids)
for response in responses:
await self._increment_vector_store_file_status(vector_store, response)

vector_store.status = VectorStoreStatus.COMPLETED.value
vector_store.last_active_at = int(time.time())

await crud_vector_store.update(id_=vector_store_id, object_=vector_store)

async def modify_existing_vector_store(
self,
vector_store_id: str,
request: ModifyVectorStoreRequest,
background_tasks: BackgroundTasks | None = None,
) -> VectorStore:
"""Modify an existing vector store given its id."""
crud_vector_store = CRUDVectorStore(db=self.db)
Expand Down Expand Up @@ -236,43 +267,65 @@ async def modify_existing_vector_store(
expires_at=old_vector_store.expires_at,
)

await crud_vector_store.update(
# Update the vector store with the new information and set status to in_progress for the duration of this function
updated_vector_store = await crud_vector_store.update(
id_=vector_store_id,
object_=new_vector_store,
) # Sets status to in_progress for the duration of this function
)

if request.file_ids:
responses = await self.index_files(
new_vector_store.id, request.file_ids
if updated_vector_store is None:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Unable to modify vector store",
)
for response in responses:
await self._increment_vector_store_file_status(
new_vector_store, response
)

new_vector_store.status = VectorStoreStatus.COMPLETED.value

last_active_at = int(time.time())
new_vector_store.last_active_at = (
last_active_at # Update after indexing files
)
expires_after, expires_at = request.get_expiry(last_active_at)

if expires_at and expires_at:
new_vector_store.expires_after = expires_after
new_vector_store.expires_at = expires_at
# Split the files, convert the chunks into vectors, and insert them into the db
if request.file_ids:
if background_tasks:
# Perform the indexing in the background
background_tasks.add_task(
self._complete_vector_store_modification,
vector_store_id,
request,
)
else:
await self._complete_vector_store_modification(
vector_store_id, request
)

return await crud_vector_store.update(
id_=vector_store_id,
object_=new_vector_store,
)
return updated_vector_store
except Exception as exc:
logging.error(exc)
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Unable to parse vector store request",
) from exc

async def _complete_vector_store_modification(
self, vector_store_id: str, request: ModifyVectorStoreRequest
):
"""Complete the vector store modification process in the background."""
crud_vector_store = CRUDVectorStore(db=self.db)
vector_store = await crud_vector_store.get(
filters=FilterVectorStore(id=vector_store_id)
)

if request.file_ids:
responses = await self.index_files(vector_store_id, request.file_ids)
for response in responses:
await self._increment_vector_store_file_status(vector_store, response)

vector_store.status = VectorStoreStatus.COMPLETED.value
last_active_at = int(time.time())
vector_store.last_active_at = last_active_at # Update after indexing files

expires_after, expires_at = request.get_expiry(last_active_at)
if expires_after and expires_at:
vector_store.expires_after = expires_after
vector_store.expires_at = expires_at

await crud_vector_store.update(id_=vector_store_id, object_=vector_store)

async def file_ids_are_valid(self, file_ids: str | list[str]) -> bool:
"""Check if the provided file ids exist"""
crud_file_object = CRUDFileObject(db=self.db)
Expand Down
Loading
Loading