Skip to content

Add Vector Text Splitting Options to the UI #1106

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
80 changes: 62 additions & 18 deletions packages/client/src/components/settings/FileTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
Table,
Typography,
useNotification,
Stack,
Select,
MenuItem,
Box,
} from '@semoss/ui';
import { Add, Delete, SimCardDownload } from '@mui/icons-material';
import { usePixel, useRootStore } from '@/hooks';
Expand Down Expand Up @@ -57,6 +61,12 @@ const StyledIcon = styled(Add)(({ theme }) => ({

const StyledFileTable = styled(Table)({ backgroundColor: 'white' });

const splittingOptions = [
{ label: 'Tokens', value: 'Tokens' },
{ label: 'Recursive', value: 'Recursive' },
{ label: 'Semantic', value: 'Semantic' },
];

interface FileTableProps {
/**
* Id of the vector engine
Expand Down Expand Up @@ -122,6 +132,8 @@ export const FileTable = (props: FileTableProps) => {
},
];

const [selectedSplitOptions, setSelectedSplitOptions] = useState('Tokens');

//grabbing ID out of props
const { id } = props;

Expand Down Expand Up @@ -227,7 +239,7 @@ export const FileTable = (props: FileTableProps) => {

// Embedding the File
const response = await monolithStore.runQuery(`
CreateEmbeddingsFromDocuments( engine= "${id}", filePaths= [${fileLocations}])
CreateEmbeddingsFromDocuments( engine= "${id}", filePaths= [${fileLocations}], splitOptions="${selectedSplitOptions}")
`);

const { output, operationType } = response.pixelReturn[0];
Expand Down Expand Up @@ -622,23 +634,55 @@ export const FileTable = (props: FileTableProps) => {
rules={{}}
render={({ field }) => {
return (
<FileDropzone
multiple={true}
value={field.value}
extensions={[
'.pdf',
'.csv',
'.txt',
'.doc',
'.ppt',
'.docx',
'.pptx',
]}
disabled={isLoading}
onChange={(newValues) => {
field.onChange(newValues);
}}
/>
<Stack>
<Box>
<Select
sx={{
mb: 2,
'& .MuiInputBase-input': {
padding: '15px',
},
}}
size="small"
fullWidth
label="Select a Split Options"
value={selectedSplitOptions}
onChange={(e) =>
setSelectedSplitOptions(
e.target.value,
)
}
>
{splittingOptions.map(
(option) => (
<MenuItem
key={option.value}
value={option.value}
>
{option.label}
</MenuItem>
),
)}
</Select>
</Box>
<FileDropzone
multiple={true}
value={field.value}
extensions={[
'.pdf',
'.csv',
'.txt',
'.doc',
'.ppt',
'.docx',
'.pptx',
]}
disabled={isLoading}
onChange={(newValues) => {
field.onChange(newValues);
}}
/>
</Stack>
);
}}
/>
Expand Down
23 changes: 20 additions & 3 deletions packages/client/src/pages/import/ImportConnectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ import { useRootStore } from '@/hooks';

import { useStepper } from '@/hooks';

interface VectorDatabaseFields {
NAME: string;
VECTOR_TYPE: string;
EMBEDDER_ENGINE_ID: string;
INDEX_CLASSES: string;
CHUNKING_STRATEGY: string;
CONTENT_LENGTH: number;
CONTENT_OVERLAP: number;
KEEP_INPUT_OUTPUT: string;
DISTANCE_METHOD: string;
SPLITTING_OPTIONS?: string;
}

const StyledBox = styled(Box)(({ theme }) => ({
boxShadow: '0px 5px 22px 0px rgba(0, 0, 0, 0.06)',
width: '100%',
Expand Down Expand Up @@ -35,7 +48,7 @@ export const ImportConnectionPage = () => {
const formSubmit = async (values: {
type: 'VECTOR' | 'STORAGE' | 'MODEL' | 'FUNCTION' | 'UPLOAD';
name: string;
fields: unknown[];
fields: VectorDatabaseFields;
secondaryFields?: unknown[];
}) => {
// let pixel = ''; // 'VECTOR' | 'STORAGE' | 'MODEL' | 'FUNCTION' | 'UPLOAD'
Expand Down Expand Up @@ -113,10 +126,13 @@ export const ImportConnectionPage = () => {
return;
} else if (values.type === 'VECTOR') {
/** Vector Database: START */

const { SPLITTING_OPTIONS, ...filteredFields } = values.fields;

const pixel = `
CreateVectorDatabaseEngine (
database=["${values.name}"],
conDetails=[${JSON.stringify(values.fields)}]
conDetails=[${JSON.stringify(filteredFields)}]
) ;
`;

Expand Down Expand Up @@ -146,7 +162,8 @@ export const ImportConnectionPage = () => {

const secondaryPixel = `CreateEmbeddingsFromDocuments(
engine="${output.database_id}",
filePaths=["${upload[0].fileLocation}"]
filePaths=["${upload[0].fileLocation}"],
splitOptions="${SPLITTING_OPTIONS}"
);`;

monolithStore.runQuery(secondaryPixel).then((response) => {
Expand Down
182 changes: 182 additions & 0 deletions packages/client/src/pages/import/import.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6742,6 +6742,32 @@ export const CONNECTION_OPTIONS = {
secondary: true,
rules: {},
},
{
fieldName: 'SPLITTING_OPTIONS',
label: 'Splitting Options',
defaultValue: 'Tokens',
options: {
component: 'select',
options: [
{
display: 'Tokens',
value: 'Tokens',
},
{
display: 'Recursive',
value: 'Recursive',
},
{
display: 'Semantic',
value: 'Semantic',
},
],
},
disabled: false,
rules: { required: false },
advanced: true,
helperText: '',
},
{
fieldName: 'DISTANCE_METHOD',
label: 'Distance Method',
Expand Down Expand Up @@ -6983,6 +7009,32 @@ export const CONNECTION_OPTIONS = {
secondary: true,
rules: {},
},
{
fieldName: 'SPLITTING_OPTIONS',
label: 'Splitting Options',
defaultValue: 'Tokens',
options: {
component: 'select',
options: [
{
display: 'Tokens',
value: 'Tokens',
},
{
display: 'Recursive',
value: 'Recursive',
},
{
display: 'Semantic',
value: 'Semantic',
},
],
},
disabled: false,
rules: { required: false },
advanced: true,
helperText: '',
},
{
fieldName: 'DIMENSION_SIZE',
label: 'Embedding Dimension Size',
Expand Down Expand Up @@ -7234,6 +7286,32 @@ export const CONNECTION_OPTIONS = {
secondary: true,
rules: {},
},
{
fieldName: 'SPLITTING_OPTIONS',
label: 'Splitting Options',
defaultValue: 'Tokens',
options: {
component: 'select',
options: [
{
display: 'Tokens',
value: 'Tokens',
},
{
display: 'Recursive',
value: 'Recursive',
},
{
display: 'Semantic',
value: 'Semantic',
},
],
},
disabled: false,
rules: { required: false },
advanced: true,
helperText: '',
},
{
fieldName: 'DISTANCE_METHOD',
label: 'Distance Method',
Expand Down Expand Up @@ -7464,6 +7542,32 @@ export const CONNECTION_OPTIONS = {
secondary: true,
rules: {},
},
{
fieldName: 'SPLITTING_OPTIONS',
label: 'Splitting Options',
defaultValue: 'Tokens',
options: {
component: 'select',
options: [
{
display: 'Tokens',
value: 'Tokens',
},
{
display: 'Recursive',
value: 'Recursive',
},
{
display: 'Semantic',
value: 'Semantic',
},
],
},
disabled: false,
rules: { required: false },
advanced: true,
helperText: '',
},
{
fieldName: 'DISTANCE_METHOD',
label: 'Distance Method',
Expand Down Expand Up @@ -7729,6 +7833,32 @@ export const CONNECTION_OPTIONS = {
secondary: true,
rules: {},
},
{
fieldName: 'SPLITTING_OPTIONS',
label: 'Splitting Options',
defaultValue: 'Tokens',
options: {
component: 'select',
options: [
{
display: 'Tokens',
value: 'Tokens',
},
{
display: 'Recursive',
value: 'Recursive',
},
{
display: 'Semantic',
value: 'Semantic',
},
],
},
disabled: false,
rules: { required: false },
advanced: true,
helperText: '',
},
{
fieldName: 'DISTANCE_METHOD',
label: 'Distance Method',
Expand Down Expand Up @@ -8054,6 +8184,32 @@ export const CONNECTION_OPTIONS = {
secondary: true,
rules: {},
},
{
fieldName: 'SPLITTING_OPTIONS',
label: 'Splitting Options',
defaultValue: 'Tokens',
options: {
component: 'select',
options: [
{
display: 'Tokens',
value: 'Tokens',
},
{
display: 'Recursive',
value: 'Recursive',
},
{
display: 'Semantic',
value: 'Semantic',
},
],
},
disabled: false,
rules: { required: false },
advanced: true,
helperText: '',
},
{
fieldName: 'DISTANCE_METHOD',
label: 'Distance Method',
Expand Down Expand Up @@ -8539,6 +8695,32 @@ export const CONNECTION_OPTIONS = {
secondary: true,
rules: {},
},
{
fieldName: 'SPLITTING_OPTIONS',
label: 'Splitting Options',
defaultValue: 'Tokens',
options: {
component: 'select',
options: [
{
display: 'Tokens',
value: 'Tokens',
},
{
display: 'Recursive',
value: 'Recursive',
},
{
display: 'Semantic',
value: 'Semantic',
},
],
},
disabled: false,
rules: { required: false },
advanced: true,
helperText: '',
},
{
fieldName: 'DISTANCE_METHOD',
label: 'Distance Method',
Expand Down