Skip to content

Commit

Permalink
refactoring logs and error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
asasvirtuais authored Aug 19, 2024
1 parent d809daa commit 0aaec99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ const mapToCone = (path: string) => (embed: EmbedResponse): PineconeRecord<Recor
})
const resolved = Promise.resolve()
export default async function main(created: string[] = [], updated: string[] = [], removed: string[] = []) {

const creating = created.length > 0 ? Promise.all(
created.map(
path => read(path)
.then(embed)
.then(mapToCone(path))
)
).then(create) : resolved
const updating = await Promise.all(

const updating = Promise.all(
updated.map(
path => read(path)
.then(embed)
.then(mapToCone(path))
)
).then(res => res.map(update))
).then(res => Promise.all(res.map(update)))

const removing = removed.length > 0 ? destroy(removed) : resolved
await Promise.all([creating, ...updating, removing]).catch(logger.error)

await Promise.all([creating, updating, removing]).catch(console.error)
}
6 changes: 3 additions & 3 deletions src/pinecone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const index = pinecone.index(config.index)

export const namespace = index.namespace(config.namespace)

export const create = (data: PineconeRecord<RecordMetadata>[]) => namespace.upsert(data).then(logger.sillier)
export const create = (data: PineconeRecord<RecordMetadata>[]) => namespace.upsert(data)

export const update = (data: PineconeRecord<RecordMetadata>) => namespace.update(data).then(logger.sillier)
export const update = (data: PineconeRecord<RecordMetadata>) => namespace.update(data)

export const destroy = (ids: string[]) => (
ids.length === 1 ? namespace.deleteOne(ids[0] as string) : namespace.deleteMany(ids)
).then(logger.sillier)
)

export default pinecone

0 comments on commit 0aaec99

Please sign in to comment.