-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display similarity search results (#107)
* Display similarity search results
- Loading branch information
Showing
10 changed files
with
259 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import path from 'path' | ||
|
||
import { ChevronDown, ChevronRight } from 'lucide-react' | ||
import { useState } from 'react' | ||
|
||
import { useApp } from '../../contexts/app-context' | ||
import { SelectVector } from '../../database/schema' | ||
import { openMarkdownFile } from '../../utils/obsidian' | ||
|
||
function SimiliartySearchItem({ | ||
chunk, | ||
}: { | ||
chunk: Omit<SelectVector, 'embedding'> & { | ||
similarity: number | ||
} | ||
}) { | ||
const app = useApp() | ||
|
||
const handleClick = () => { | ||
openMarkdownFile(app, chunk.path, chunk.metadata.startLine) | ||
} | ||
return ( | ||
<div onClick={handleClick} className="smtcmp-similarity-search-item"> | ||
<div className="smtcmp-similarity-search-item__path"> | ||
{path.basename(chunk.path)} | ||
</div> | ||
<div className="smtcmp-similarity-search-item__line-numbers"> | ||
{`${chunk.metadata.startLine} - ${chunk.metadata.endLine}`} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default function SimilaritySearchResults({ | ||
similaritySearchResults, | ||
}: { | ||
similaritySearchResults: (Omit<SelectVector, 'embedding'> & { | ||
similarity: number | ||
})[] | ||
}) { | ||
const [isOpen, setIsOpen] = useState(false) | ||
|
||
return ( | ||
<div className="smtcmp-similarity-search-results"> | ||
<div | ||
onClick={() => { | ||
setIsOpen(!isOpen) | ||
}} | ||
className="smtcmp-similarity-search-results__trigger" | ||
> | ||
{isOpen ? <ChevronDown size={16} /> : <ChevronRight size={16} />} | ||
<div>Show Referenced Documents ({similaritySearchResults.length})</div> | ||
</div> | ||
{isOpen && ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
{similaritySearchResults.map((chunk) => ( | ||
<SimiliartySearchItem key={chunk.id} chunk={chunk} /> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.