Skip to main content

VectorStoreService

Upgather SDK


Upgather SDK / VectorStoreService

Class: VectorStoreService

Defined in: lib/services/VectorStoreService.ts:97

Orchestrates file operations (add/update/remove) in your OpenAI vector store, scoped by eventId in Strapi.

Constructors

new VectorStoreService()

new VectorStoreService(strapi, logger?): VectorStoreService

Defined in: lib/services/VectorStoreService.ts:106

Creates an instance of VectorStoreService.

Parameters

strapi

StrapiService

The StrapiService instance for interacting with Strapi CMS

logger?

LoggerInterface

Optional logger instance. If not provided, uses a silent logger.

Returns

VectorStoreService

Methods

addFile()

addFile(eventId, file, filename?, options?): Promise<UploadedFile>

Defined in: lib/services/VectorStoreService.ts:232

Add a new file to the vector store for a given event.

Parameters

eventId

string

Strapi event identifier.

file

File to upload (Buffer, Readable, or FileObject).

FileObject | Buffer<ArrayBufferLike> | Readable

filename?

string

Optional filename for buffer uploads.

options?

VectorStoreOptions

Optional configuration including OpenAI key.

Returns

Promise<UploadedFile>

The uploaded file information.

Throws

Error if upload or association fails.


getVectorConfig()

getVectorConfig(eventId, providedKey?): Promise<{ openAiKey: string; orgKey: string; vectorStoreId: string; }>

Defined in: lib/services/VectorStoreService.ts:121

Fetches the OpenAI API key and vector-store ID for a given event.

Parameters

eventId

string

The Strapi eventId (api::event.event → eventId)

providedKey?

string

Optional OpenAI key to use instead of the org key

Returns

Promise<{ openAiKey: string; orgKey: string; vectorStoreId: string; }>

An object containing:

  • openAiKey: the OpenAI key (provided key takes precedence)
  • vectorStoreId: the vector store identifier (VectorStore.vector_store_id)
  • orgKey: the organization's key (for fallback purposes)

Throws

Error if the event, organization, or vector store is missing or mis-configured.


removeFile()

removeFile(eventId, fileId, options?): Promise<FileDeleted & object>

Defined in: lib/services/VectorStoreService.ts:444

Remove a file from the vector store and delete it from OpenAI's file storage.

Parameters

eventId

string

Strapi event identifier.

fileId

string

ID of the file to remove.

options?

VectorStoreOptions

Optional configuration including OpenAI key.

Returns

Promise<FileDeleted & object>

The OpenAI delete response (usually { deleted: true }).

Throws

Error if disassociation or deletion fails.

Remarks

This method performs two operations:

  1. Removes the file association from the vector store
  2. Deletes the actual file from OpenAI's file storage

updateFile()

updateFile(eventId, oldFileId, newFile, filename?, options?): Promise<UploadedFile>

Defined in: lib/services/VectorStoreService.ts:339

Replace an existing file in the vector store. Under the hood, disassociates & deletes the old file, then uploads & re-associates.

Parameters

eventId

string

Strapi event identifier.

oldFileId

string

ID of the file to replace.

newFile

New file (Buffer, Readable, or FileObject).

FileObject | Buffer<ArrayBufferLike> | Readable

filename?

string

Optional filename for buffer uploads.

options?

VectorStoreOptions

Optional configuration including OpenAI key.

Returns

Promise<UploadedFile>

The new uploaded file information.

Throws

Error if any step fails.