Skip to content

Commit

Permalink
add similiarity search
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshack committed Mar 22, 2024
1 parent 88a26f0 commit 7d0aa0c
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 63 deletions.
23 changes: 21 additions & 2 deletions components/DatasetInfoExtended.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import Typewriter from './Typewriter'
import { LoaderIcon } from '@/components/ui/icons/loader'
import { AiText } from '@/components/AiText'
import { AttributeTable } from '@/components/AttributeTable'
import { SearchIcon } from '@/components/ui/icons/search'

export function DatasetInfoExtended({ contentDataset, inputText }) {
export function DatasetInfoExtended({ contentDataset, inputText, setSimilarSearchText }) {
const { copyToClipboard, hasCopied } = useCopyToClipboard()

console.log('contentDataset', contentDataset)

const buttonClass = 'w-max flex bg-odis-light !text-white p-2 mr-2 rounded-md hover:bg-active '
const buttonClass =
'align-center w-max flex bg-odis-light !text-white p-2 mr-2 rounded-md hover:bg-active '

return (
<div>
Expand Down Expand Up @@ -87,6 +89,22 @@ export function DatasetInfoExtended({ contentDataset, inputText }) {
{!hasCopied ? contentDataset['Typ'] + ' kopieren' : 'kopiert!'}
</div>
</button>
<button
onClick={() => setSimilarSearchText(contentDataset['Titel'])}
className={buttonClass}
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
className="mr-2"
viewBox="0 0 16 16"
>
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0" />
</svg>
ähnlichen Daten
</button>
</div>

{contentDataset['Fisbroker URL'] && (
Expand All @@ -98,6 +116,7 @@ export function DatasetInfoExtended({ contentDataset, inputText }) {
. Hier erhälst du Detailinformationen wie letzte Aktualisierungen, Granularität, etc.
</div>
)}

{contentDataset['Attribute'] && <AttributeTable contentDataset={contentDataset} />}

<AiText content={contentDataset.rawContent} inputText={inputText} />
Expand Down
8 changes: 6 additions & 2 deletions components/DatasetInfoRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function parseEmbeddingContent(text) {
}

export function DatasetInfoRow(props) {
const { result, inputText, typeFilterValue } = props
const { result, inputText, typeFilterValue, setSimilarSearchText } = props

const [showExtraInfo, setShowExtraInfo] = useState<boolean>(false)
let content = result && result.content ? parseEmbeddingContent(result.content) : {}
Expand Down Expand Up @@ -79,7 +79,11 @@ export function DatasetInfoRow(props) {
{showExtraInfo && (
<tr colSpan={3}>
<td colSpan={3} className="">
<DatasetInfoExtended contentDataset={content} inputText={inputText} />
<DatasetInfoExtended
contentDataset={content}
inputText={inputText}
setSimilarSearchText={setSimilarSearchText}
/>
</td>
</tr>
)}
Expand Down
18 changes: 13 additions & 5 deletions components/SearchAI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function SearchAI({ language }) {
const [searchResults, setSearchResults] = useState<Array<any> | boolean>(false) // @to < Array || false >
const [creativeSearch, setCreativeSearch] = useState(false)
const [showExamples, setShowExamples] = useState(true)

const [typeFilterValue, setTypeFilterValue] = useState('WFS & WMS')
const [similarSearchText, setSimilarSearchText] = useState('')

async function getSearchResults(inputText) {
let data
Expand All @@ -28,7 +28,7 @@ export function SearchAI({ language }) {
`/api/get-embeddings/?messages=${inputText}&matchthreshold=${
// creativeSearch ? 0.3 : 0.78
// 0.3
0.78
0.3
}`,
{
cache: process.env.NODE_ENV === 'development' ? 'no-store' : 'default',
Expand All @@ -47,6 +47,13 @@ export function SearchAI({ language }) {
}
}

useEffect(() => {
if (similarSearchText) {
setInputText(similarSearchText)
searchForEmbedding(similarSearchText)
}
}, [similarSearchText])

async function searchForEmbedding(inputText) {
if (isLoading || inputText === '') {
return
Expand Down Expand Up @@ -130,16 +137,17 @@ export function SearchAI({ language }) {
<table className="w-full">
<tbody className="">
<tr className="border-b-[1px] text-lg text-left">
<th className="p-4 w-2/5">Datensatztitel</th>
<th className="p-4 w-2/5">Übereinstimmung</th>
<th className="w-1/5"></th>
<th className="p-4">Datensatztitel</th>
<th className="p-4">Übereinstimmung</th>
<th className=""></th>
</tr>
{searchResults.map((result) => (
<React.Fragment key={result.id}>
<DatasetInfoRow
result={result}
inputText={inputText}
typeFilterValue={typeFilterValue}
setSimilarSearchText={setSimilarSearchText}
></DatasetInfoRow>
</React.Fragment>
))}
Expand Down
Loading

0 comments on commit 7d0aa0c

Please sign in to comment.