-
Notifications
You must be signed in to change notification settings - Fork 0
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: update loops and add publish workflows #2
Conversation
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
passages.forEach((item) => { | ||
const match = item.match(/\[(\d+)\]/g); | ||
for (let i = 0; i < passages.length; i++) { | ||
const match = passages[i].match(/\[(\d+)\]/g); | ||
if (match) { | ||
const index = parseInt(match[0].replace(/\[|\]/g, "")); | ||
result.push(list[index - 1][idKey]); | ||
const index = parseInt(match[0].replace(/\[|\]/g, ""), 10); | ||
if (index > 0 && index <= list.length) { | ||
// Check to ensure index is within bounds to prevent index -1/out of bounds error. | ||
result.push(list[index - 1][idKey]); | ||
} | ||
} | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Added a check to ensure that the index derived from the match is within the bounds of the list array
- Using
for
as it recdces the overhead of calling a function for each item in passages.
rankLists.forEach((list) => { | ||
list.forEach((item, index) => { | ||
const rrfScore = 1 / (c + index + 1); // index is zero-based, add 1 for correct rank | ||
const currentScore = scores.get(item[idKey] as string) || 0; | ||
scores.set(item[idKey] as string, currentScore + rrfScore); | ||
}); | ||
}); | ||
for (let i = 0; i < rankLists.length; i++) { | ||
const list = rankLists[i]; | ||
for (let index = 0; index < list.length; index++) { | ||
const item = list[index]; | ||
const itemId = item[idKey] as string; // Cast once and reuse | ||
const rrfScore = 1 / (c + index + 1); // Compute RRF score | ||
const currentScore = scores.get(itemId) || 0; // Get current score, default to 0 | ||
scores.set(itemId, currentScore + rrfScore); // Update score | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The conversion item[idKey] as string is done twice per item, which is redundant, so IMO we can compute it once and reuse it 😶
- Minimize map accesses as reducing the amount of ops can give more perf. benefits
- Used
for
loops here as well instead offorEach
ranks.forEach((rank) => { | ||
let match = batch.filter((item) => item.startsWith(rank)); | ||
if (match.length > 0) { | ||
result.push(match[0]); | ||
for (let i = 0; i < ranks.length; i++) { | ||
const rank = ranks[i]; | ||
let matchFound = false; | ||
for (let j = 0; j < batch.length; j++) { | ||
if (batch[j].startsWith(rank)) { | ||
result.push(batch[j]); | ||
matchFound = true; | ||
break; | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We can avoid using filter inside a for loop as it iterates over the entire
batch
for eachrank
- Used
break
to exit early in case so that we prevent unnecessary iterations
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
Thanks @lucasjacks0n :) |
Description:
npm publish
workflow (Needs NPM Secret to be added to settings).env
for API Keys/Secrets