Skip to content
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
41 changes: 40 additions & 1 deletion packages/components/nodes/vectorstores/Milvus/Milvus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ class Milvus_VectorStores implements INode {
additionalParams: true,
optional: true
},
{
label: 'Metric Type',
name: 'metricType',
description: 'Distance metric for similarity search. Default to L2 (Euclidean distance)',
type: 'options',
options: [
{
label: 'L2 (Euclidean Distance)',
name: 'L2'
},
{
label: 'IP (Inner Product)',
name: 'IP'
},
{
label: 'COSINE (Cosine Similarity)',
name: 'COSINE'
}
],
default: 'L2',
additionalParams: true,
optional: true
},
{
label: 'Secure',
name: 'secure',
Expand Down Expand Up @@ -194,6 +217,9 @@ class Milvus_VectorStores implements INode {
// partition
const partitionName = nodeData.inputs?.milvusPartition ?? '_default'

// metric type
const metricType = (nodeData.inputs?.metricType as string) ?? 'L2'

// init MilvusLibArgs
const milVusArgs: MilvusLibArgs = {
url: address,
Expand All @@ -217,6 +243,11 @@ class Milvus_VectorStores implements INode {
if (milvusUser) milVusArgs.username = milvusUser
if (milvusPassword) milVusArgs.password = milvusPassword

// Set metric type for index creation
milVusArgs.indexCreateParams = {
metric_type: MetricType[metricType as keyof typeof MetricType]
}

const flattenDocs = docs && docs.length ? flatten(docs) : []
const finalDocs = []
for (let i = 0; i < flattenDocs.length; i += 1) {
Expand Down Expand Up @@ -276,6 +307,9 @@ class Milvus_VectorStores implements INode {
// partition
const partitionName = nodeData.inputs?.milvusPartition ?? '_default'

// metric type
const metricType = (nodeData.inputs?.metricType as string) ?? 'L2'

// init MilvusLibArgs
const milVusArgs: MilvusLibArgs = {
url: address,
Expand All @@ -300,6 +334,11 @@ class Milvus_VectorStores implements INode {
if (milvusUser) milVusArgs.username = milvusUser
if (milvusPassword) milVusArgs.password = milvusPassword

// Set metric type for index creation
milVusArgs.indexCreateParams = {
metric_type: MetricType[metricType as keyof typeof MetricType]
}

let milvusFilter = _milvusFilter
if (isFileUploadEnabled && options.chatId) {
if (milvusFilter) milvusFilter += ` OR ${FLOWISE_CHATID} == "${options.chatId}" OR NOT EXISTS(${FLOWISE_CHATID})`
Expand Down Expand Up @@ -471,7 +510,7 @@ class MilvusUpsert extends Milvus {
field_name: this.vectorField,
index_name: `myindex_${Date.now().toString()}`,
index_type: IndexType.AUTOINDEX,
metric_type: MetricType.L2
metric_type: this.indexCreateParams?.metric_type || MetricType.L2
})
if (resp.error_code !== ErrorCode.SUCCESS) {
throw new Error(`Error creating index`)
Expand Down
31 changes: 30 additions & 1 deletion packages/ui/src/ui-component/dialog/ShareWithWorkspaceDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { enqueueSnackbar as enqueueSnackbarAction, closeSnackbar as closeSnackba
import { cloneDeep } from 'lodash'

// Material
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Box, Stack, OutlinedInput, Typography } from '@mui/material'
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Box, Stack, OutlinedInput, Typography, Checkbox, FormControlLabel } from '@mui/material'

// Project imports
import { StyledButton } from '@/ui-component/button/StyledButton'
Expand Down Expand Up @@ -47,6 +47,28 @@ const ShareWithWorkspaceDialog = ({ show, dialogProps, onCancel, setError }) =>
const [outputSchema, setOutputSchema] = useState([])

const [name, setName] = useState('')
const [selectAll, setSelectAll] = useState(false)

// Handle select all / deselect all
const handleSelectAllChange = (event) => {
const checked = event.target.checked
setSelectAll(checked)
setOutputSchema((prevRows) => {
return prevRows.map((row) => ({
...row,
shared: checked
}))
})
}

// Update selectAll state when individual rows change
useEffect(() => {
if (outputSchema.length > 0) {
const allSelected = outputSchema.every((row) => row.shared)
const noneSelected = outputSchema.every((row) => !row.shared)
setSelectAll(allSelected ? true : noneSelected ? false : false)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ternary logic here is redundant. Since allSelected is only true when all rows are shared, and in all other cases (none selected or some selected) the selectAll state should be false, you can simplify this to just setSelectAll(allSelected).

Suggested change
setSelectAll(allSelected ? true : noneSelected ? false : false)
setSelectAll(allSelected)

}
}, [outputSchema])

const onRowUpdate = (newRow) => {
setTimeout(() => {
Expand Down Expand Up @@ -187,6 +209,13 @@ const ShareWithWorkspaceDialog = ({ show, dialogProps, onCancel, setError }) =>
<OutlinedInput id='name' type='string' disabled={true} fullWidth placeholder={name} value={name} name='name' />
</Box>
<Box sx={{ p: 2 }}>
<Stack direction='row' alignItems='center' justifyContent='space-between' sx={{ mb: 1 }}>
<Typography variant='overline'>Workspaces</Typography>
<FormControlLabel
control={<Checkbox checked={selectAll} onChange={handleSelectAllChange} size='small' />}
label={<Typography variant='body2'>Select All</Typography>}
/>
</Stack>
<Grid columns={columns} rows={outputSchema} onRowUpdate={onRowUpdate} />
</Box>
</DialogContent>
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/ui-component/tooltip/MoreItemsTooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Tooltip, Typography } from '@mui/material'
import { styled } from '@mui/material/styles'
import PropTypes from 'prop-types'

const StyledOl = styled('ol')(() => ({
const StyledUl = styled('ul')(() => ({
paddingLeft: 20,
margin: 0
}))
Expand All @@ -17,13 +17,13 @@ const MoreItemsTooltip = ({ images, children }) => {
return (
<Tooltip
title={
<StyledOl>
<StyledUl>
{images.map((img) => (
<StyledLi key={img.imageSrc || img.label}>
<Typography>{img.label}</Typography>
</StyledLi>
))}
</StyledOl>
</StyledUl>
}
placement='top'
>
Expand Down