Skip to content

Commit

Permalink
[FIX] Document pinning does not count in query mode (#1250)
Browse files Browse the repository at this point in the history
* if document is pinned, do not give queryRefusalResponse message

* forgot embed.js patch

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
  • Loading branch information
shatfield4 and timothycarambat committed May 2, 2024
1 parent 244ce2e commit d02013f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion server/utils/chats/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ async function streamChatWithForEmbed(

// If in query mode and no sources are found, do not
// let the LLM try to hallucinate a response or use general knowledge
if (chatMode === "query" && sources.length === 0) {
if (
chatMode === "query" &&
sources.length === 0 &&
pinnedDocIdentifiers.length === 0
) {
writeResponseChunk(response, {
id: uuid,
type: "textResponse",
Expand Down
8 changes: 6 additions & 2 deletions server/utils/chats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ async function chatWithWorkspace(
contextTexts = [...contextTexts, ...vectorSearchResults.contextTexts];
sources = [...sources, ...vectorSearchResults.sources];

// If in query mode and no sources are found, do not
// If in query mode and no sources are found from the vector search and no pinned documents, do not
// let the LLM try to hallucinate a response or use general knowledge and exit early
if (chatMode === "query" && sources.length === 0) {
if (
chatMode === "query" &&
vectorSearchResults.sources.length === 0 &&
pinnedDocIdentifiers.length === 0
) {
return {
id: uuid,
type: "textResponse",
Expand Down
8 changes: 6 additions & 2 deletions server/utils/chats/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ async function streamChatWithWorkspace(
contextTexts = [...contextTexts, ...vectorSearchResults.contextTexts];
sources = [...sources, ...vectorSearchResults.sources];

// If in query mode and no sources are found, do not
// If in query mode and no sources are found from the vector search and no pinned documents, do not
// let the LLM try to hallucinate a response or use general knowledge and exit early
if (chatMode === "query" && sources.length === 0) {
if (
chatMode === "query" &&
sources.length === 0 &&
pinnedDocIdentifiers.length === 0
) {
writeResponseChunk(response, {
id: uuid,
type: "textResponse",
Expand Down

0 comments on commit d02013f

Please sign in to comment.