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

fix: buggy indexing of array for reranking 🐞 #515

Merged
merged 1 commit into from
Sep 14, 2024
Merged
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
20 changes: 10 additions & 10 deletions packages/core/src/modules/slack/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ async function getMostRelevantThreads(
return !options.exclude?.includes(match.id);
});

const messages = await Promise.all(
let messages = await Promise.all(
filteredMatches.map(async (match) => {
const [thread, replies] = await Promise.all([
db
Expand Down Expand Up @@ -517,22 +517,22 @@ async function getMostRelevantThreads(
})
);

// We filter out any messages that don't have replies, since this
// is most likely a question that never got answered.
messages = messages.filter((message) => {
return !!message.replies.length;
});

// This next step is an important one -- we're going to rerank the messages
// based on their relevance to the question. This helps us get the most
// relevant threads to the LLM. Reranking models are different from
// vector search which are optimized for fast retrieval. Reranking models are
// more accurate at assessing relevance, but they are slower and more
// expensive to compute.

const documents = messages
.filter((message) => {
// We filter out any messages that don't have replies, since this
// is most likely a question that never got answered.
return !!message.replies.length;
})
.map((message) => {
return [message.createdAt, message.message, message.replies].join('\n');
});
const documents = messages.map((message) => {
return [message.createdAt, message.message, message.replies].join('\n');
});

const rerankingResult = await rerankDocuments(question, documents, {
topK: options.topK,
Expand Down