Skip to content

Commit f948df7

Browse files
committed
cleanup: add file_id to chunks created from pdf2md and remove the file-context from search-component
1 parent e785e83 commit f948df7

File tree

8 files changed

+20
-81
lines changed

8 files changed

+20
-81
lines changed

clients/search-component/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"import": "./dist/vanilla/index.js"
2020
}
2121
},
22-
"version": "0.2.57",
22+
"version": "0.2.58",
2323
"license": "MIT",
2424
"homepage": "https://github.com/devflowinc/trieve/tree/main/clients/search-component",
2525
"scripts": {

clients/search-component/src/TrieveModal/Search/PdfItem.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from "react";
22
import { PdfChunk } from "../../utils/types";
3-
import { useFileContext } from "../../utils/hooks/file-context";
43
import { FileDTO } from "trieve-ts-sdk";
54
import { useModalState } from "../../utils/hooks/modal-context";
65
import { cached } from "../../utils/cache";
@@ -26,7 +25,7 @@ const getPresignedUrl = async (
2625
baseUrl: string,
2726
datasetId: string,
2827
fileId: string,
29-
apiKey: string,
28+
apiKey: string
3029
) => {
3130
const params = {
3231
content_type: "application/pdf",
@@ -51,7 +50,6 @@ const getPresignedUrl = async (
5150
export const PdfItem = (props: Props) => {
5251
const [presigned, setPresigned] = useState<string | null>(null);
5352
const toHighlight = extractMarkedContent(props.item.chunk.highlight || "");
54-
const fileCtx = useFileContext();
5553
const state = useModalState();
5654
const [hasFoundMatch, setHasFoundMatch] = useState(true);
5755

@@ -61,11 +59,11 @@ export const PdfItem = (props: Props) => {
6159
return getPresignedUrl(
6260
state.props.baseUrl || "http://localhost:8090",
6361
state.props.datasetId,
64-
fileCtx.files[props.item.chunk.metadata.file_name],
65-
state.props.apiKey,
62+
props.item.chunk.metadata.file_id,
63+
state.props.apiKey
6664
);
6765
}, `file-presigned:${props.item.chunk.metadata.file_name}`);
68-
console.log(presignedUrlResult);
66+
6967
setPresigned(presignedUrlResult);
7068
};
7169

clients/search-component/src/TrieveModal/index.css

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ body {
6262
&.chat-modal-mobile {
6363
@apply flex flex-col top-0 sm:top-[calc(40%-30vh)] pt-4 max-h-[100vh] w-full sm:w-[90vw] rounded-none sm:rounded-lg;
6464

65-
&.docs {
65+
&.docs, &.pdf {
6666
@apply h-screen sm:h-auto;
6767
}
6868

@@ -71,8 +71,8 @@ body {
7171
}
7272
}
7373

74-
.trieve-elements-docs {
75-
@apply pr-2 scroll-smooth;
74+
.trieve-elements-docs, .trieve-elements-pdf {
75+
@apply scroll-smooth;
7676

7777
.item-group-container {
7878
@apply border-b border-gray-300 mb-5;
@@ -98,12 +98,8 @@ body {
9898
}
9999
}
100100

101-
.trieve-elements-pdf {
102-
@apply p-2;
103-
}
104-
105101
.pdf-results {
106-
@apply grid grid-cols-2 pl-2;
102+
@apply grid grid-cols-2;
107103
}
108104

109105
.no-results {
@@ -138,7 +134,7 @@ body {
138134
.mode-switch-wrapper {
139135
@apply flex items-center justify-end mt-2 absolute top-2.5 right-4 z-30 font-medium;
140136

141-
&.docs.chat {
137+
&.docs.chat, &.pdf.chat {
142138
@apply top-0;
143139

144140
right: calc(max(calc(50% - 39.85rem), 4rem) + 0.25rem);
@@ -278,7 +274,7 @@ body {
278274
}
279275

280276
.trieve-powered {
281-
@apply flex items-center justify-end select-none cursor-pointer text-sm text-center;
277+
@apply flex items-center justify-end select-none cursor-pointer text-sm text-center gap-1;
282278
background-color: var(--bg-color);
283279

284280
img {
@@ -757,14 +753,14 @@ body {
757753
}
758754

759755
input {
760-
@apply rounded-none mb-0;
756+
@apply rounded-md mb-0;
761757
}
762758
}
763759

764760
ul {
765761
&:not(.chat-ul) {
766762
@apply overflow-y-auto overflow-x-hidden max-h-[calc(80vh-130px)] sm:max-h-[calc(60vh-130px)];
767-
&:not(.trieve-elements-docs) {
763+
&:not(.trieve-elements-docs, .trieve-elements-pdf) {
768764
@apply max-h-[calc(98vh-130px)] sm:max-h-[calc(60vh-130px)];
769765

770766
&:not(.commands) &:not(.trieve-elements-ecommerce) {
@@ -774,7 +770,7 @@ body {
774770
}
775771

776772
&:not(.chat-ul):not(.trieve-elements-ecommerce) {
777-
@apply pl-0 mx-0;
773+
@apply pl-2 pr-0.5 mx-0;
778774
}
779775
}
780776

clients/search-component/src/TrieveModal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const Modal = () => {
4040
const viewportHeight = window.visualViewport?.height;
4141
const chatOuterWrapper = document.querySelector(".chat-outer-wrapper");
4242

43-
if ((window.visualViewport?.width ?? 1000) <= 768) {
43+
if ((window.visualViewport?.width ?? 1000) <= 640) {
4444
const trieveSearchModal = document.getElementById("trieve-search-modal");
4545
if (trieveSearchModal) {
4646
trieveSearchModal.style.maxHeight = `calc(${viewportHeight}px - ${

clients/search-component/src/utils/hooks/file-context.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

clients/search-component/src/utils/hooks/modal-context.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
searchWithTrieve,
2323
getPagefindIndex,
2424
} from "../trieve";
25-
import { FileContextProvider } from "./file-context";
2625

2726
export const ALL_TAG = {
2827
tag: "all",
@@ -455,7 +454,7 @@ const ModalProvider = ({
455454
tagCounts,
456455
}}
457456
>
458-
<FileContextProvider>{children}</FileContextProvider>
457+
{children}
459458
</ModalContext.Provider>
460459
);
461460
};

clients/search-component/src/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type PdfChunk = {
4141
metadata: {
4242
file_name: string;
4343
page_num: number;
44+
file_id: string;
4445
};
4546
};
4647
highlights: string[];

server/src/bin/file-worker.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,13 @@ async fn upload_file(
521521
.map(|mut metadata| {
522522
metadata["page_num"] = serde_json::json!(page.page_num);
523523
metadata["file_name"] = serde_json::json!(task_response.file_name);
524+
metadata["file_id"] = serde_json::json!(file_id);
524525
metadata
525526
})
526527
.or(Some(serde_json::json!({
527528
"page_num": page.page_num,
528-
"file_name": task_response.file_name
529+
"file_name": task_response.file_name,
530+
"file_id": file_id
529531
})));
530532

531533
let create_chunk_data = ChunkReqPayload {

0 commit comments

Comments
 (0)