Skip to content
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
38 changes: 38 additions & 0 deletions src/components/source-row.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,44 @@ describe("SourceRow", () => {
expect(screen.getByText("Processed · 3 chunks")).toBeTruthy();
});

it("labels unlocalized remote documents as processed without chunk counts", () => {
const onToggleIncluded = vi.fn();

render(
React.createElement(SourceRow, {
isArchiving: false,
isSelected: false,
onSelect: vi.fn(),
onToggleIncluded,
source: {
id: "knowhere-doc:default:doc_remote",
kind: "remote",
mimeType: "application/pdf",
title: "remote.pdf",
status: "ready",
chunkCount: 4,
documentId: "doc_remote",
excludedFromQuery: false,
},
}),
);

const checkbox = screen.getByRole("checkbox", {
name: "Use remote.pdf in answers",
});

expect(screen.getByText("Processed")).toBeTruthy();
expect(screen.queryByText("Processed · 4 chunks")).toBeNull();
expect(checkbox.getAttribute("aria-checked")).toBe("true");

fireEvent.click(checkbox);

expect(onToggleIncluded).toHaveBeenCalledWith(
"knowhere-doc:default:doc_remote",
false,
);
});

it("shows source archive loading locally", () => {
render(
React.createElement(SourceRow, {
Expand Down
5 changes: 2 additions & 3 deletions src/components/source-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function SourceRow({
const isFailed = source.status === "failed";
const canRetry = isFailed && source.originalFile !== undefined;
const isLibrarySource = source.officialLibrary !== undefined;
const isRemoteSource = source.kind === "remote";

const iconBg = fileIconTint(source.title);

Expand All @@ -63,7 +62,7 @@ export function SourceRow({
>
<Checkbox
checked={!source.excludedFromQuery}
disabled={!isReady || !onToggleIncluded || isAdding || isRemoteSource}
disabled={!isReady || !onToggleIncluded || isAdding}
onCheckedChange={(checked) =>
onToggleIncluded?.(source.id, checked === true)
}
Expand Down Expand Up @@ -193,11 +192,11 @@ export function SourceRow({

function getReadySourceLabel(source: SourceView): string {
if (source.officialLibrary !== undefined) return "Official Library";
if (source.kind === "remote") return "Remote";
return "Processed";
}

function getReadySourceStatusText(source: SourceView): string {
if (source.kind === "remote") return getReadySourceLabel(source);
if (typeof source.chunkCount !== "number") return getReadySourceLabel(source);
return `${getReadySourceLabel(source)} · ${source.chunkCount} chunks`;
}
Expand Down
6 changes: 3 additions & 3 deletions src/domains/chat/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("answerQuestionWithRetrieval", () => {
question: "What does the document say?",
namespace: "notebook-workspace",
sources,
excludedSourceIds: ["source_2"],
excludedSourceIds: ["source_2", "knowhere-doc:default:doc_remote"],
retrieval,
generateAnswer,
messages: [],
Expand All @@ -79,13 +79,13 @@ describe("answerQuestionWithRetrieval", () => {
topK: 8,
useAgentic: true,
dataType: 1,
excludeDocumentIds: ["doc_excluded"],
excludeDocumentIds: ["doc_excluded", "doc_remote"],
});
expect(generateAnswer).toHaveBeenCalledWith({
question: "What does the document say?",
messages: [],
sources,
excludedSourceIds: ["source_2"],
excludedSourceIds: ["source_2", "knowhere-doc:default:doc_remote"],
searchSources: expect.any(Function),
});
expect(answer).toEqual({
Expand Down
9 changes: 8 additions & 1 deletion src/domains/chat/retrieval.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { RetrievalQueryParams } from "@ontos-ai/knowhere-sdk"

import type { Source } from "@/infrastructure/db/schema"
import { decodeRemoteSourceId } from "@/domains/sources/remote-library"

const RETRIEVAL_QUERY_CHAR_LIMIT = 600

Expand All @@ -25,10 +26,16 @@ export function excludeDocuments(
excludedSourceIds: readonly string[],
): Pick<RetrievalQueryParams, "excludeDocumentIds"> {
const excluded = new Set(excludedSourceIds)
const documentIds = sources
const localDocumentIds = sources
.filter((source) => excluded.has(source.id))
.map((source) => source.knowhereDocumentId)
.filter((documentId): documentId is string => Boolean(documentId))
const remoteDocumentIds = excludedSourceIds
.map((sourceId) => decodeRemoteSourceId(sourceId)?.documentId)
.filter((documentId): documentId is string => Boolean(documentId))
const documentIds = Array.from(
new Set([...localDocumentIds, ...remoteDocumentIds]),
)

return documentIds.length > 0 ? { excludeDocumentIds: documentIds } : {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/domains/sources/remote-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function toRemoteSourceView(document: RemoteDocument): SourceView {
mimeType: document.mimeType ?? "application/octet-stream",
status: document.status,
documentId: document.documentId,
excludedFromQuery: true,
excludedFromQuery: false,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/domains/sources/route-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe("source route service", () => {
mimeType: "application/pdf",
status: "ready",
documentId: "doc_default",
excludedFromQuery: true,
excludedFromQuery: false,
},
{
id: "knowhere-doc:notebook-workspace_1:doc_legacy",
Expand All @@ -311,7 +311,7 @@ describe("source route service", () => {
mimeType: "application/octet-stream",
status: "ready",
documentId: "doc_legacy",
excludedFromQuery: true,
excludedFromQuery: false,
},
]);
});
Expand Down
Loading