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

Bugfix/implement missing delete method on pgvector #3180

Merged
merged 1 commit into from
Sep 12, 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
12 changes: 12 additions & 0 deletions packages/components/nodes/vectorstores/Postgres/Postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ class Postgres_VectorStores implements INode {
return await similaritySearchVectorWithScore(query, k, tableName, postgresConnectionOptions, filter)
}

vectorStore.delete = async (params: { ids: string[] }): Promise<void> => {
const { ids } = params

if (ids?.length) {
try {
vectorStore.appDataSource.getRepository(vectorStore.documentEntity).delete(ids)
} catch (e) {
console.error('Failed to delete')
}
}
}

await recordManager.createSchema()

const res = await index({
Expand Down
26 changes: 21 additions & 5 deletions packages/server/src/services/documentstore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,8 @@ const processAndSaveChunks = async (data: IDocumentStoreLoaderForPreview) => {
const newLoaderId = data.id ?? uuidv4()
const found = existingLoaders.find((ldr: IDocumentStoreLoader) => ldr.id === newLoaderId)
if (found) {
// clean up the current status and mark the loader as pending_sync
found.totalChunks = 0
found.totalChars = 0
found.status = DocumentStoreStatus.SYNCING
entity.loaders = JSON.stringify(existingLoaders)
const foundIndex = existingLoaders.findIndex((ldr: IDocumentStoreLoader) => ldr.id === newLoaderId)

if (!data.loaderId) data.loaderId = found.loaderId
if (!data.loaderName) data.loaderName = found.loaderName
if (!data.loaderConfig) data.loaderConfig = found.loaderConfig
Expand All @@ -611,6 +608,25 @@ const processAndSaveChunks = async (data: IDocumentStoreLoaderForPreview) => {
if (found.credential) {
data.credential = found.credential
}

let loader: IDocumentStoreLoader = {
...found,
loaderId: data.loaderId,
loaderName: data.loaderName,
loaderConfig: data.loaderConfig,
splitterId: data.splitterId,
splitterName: data.splitterName,
splitterConfig: data.splitterConfig,
totalChunks: 0,
totalChars: 0,
status: DocumentStoreStatus.SYNCING
}
if (data.credential) {
loader.credential = data.credential
}

existingLoaders[foundIndex] = loader
entity.loaders = JSON.stringify(existingLoaders)
} else {
let loader: IDocumentStoreLoader = {
id: newLoaderId,
Expand Down
Loading