-
Notifications
You must be signed in to change notification settings - Fork 12.2k
add retrieval
example
#6193
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
Merged
ggerganov
merged 21 commits into
ggml-org:master
from
mscheong01:add-`retrieval`-example
Mar 25, 2024
Merged
add retrieval
example
#6193
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
eb760a9
add `retrieval` example
mscheong01 50f9967
add README
mscheong01 751787e
minor fixes
mscheong01 c1e5575
cast filepos on print
mscheong01 d33a015
remove use of variable sized array
mscheong01 208e1f0
store similarities in separate vector
mscheong01 789a194
print error on insufficient batch size
mscheong01 7d819d0
fix error message printing
mscheong01 e16279e
assign n_batch value to n_ubatch
mscheong01 f9dc033
fix param definitions
mscheong01 56b7db9
define retrieval-only parameters in retrieval.cpp
mscheong01 5d02fe9
fix `--context-file` option to be provided multiple times for multipl…
mscheong01 3073b38
use vector for `query_emb`
mscheong01 0796bcb
add usage description in README
mscheong01 3cb7567
Merge branch 'master' into add-`retrieval`-example
mscheong01 0cacdec
fix merge conflict
mscheong01 09eeea6
fix usage printing
mscheong01 ecdcb67
remove seed setting
mscheong01 d7fa7a6
fix lint
mscheong01 eb5fd2d
increase file read buffer size
mscheong01 f6be52d
retrieval : minor
ggerganov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
set(TARGET retrieval) | ||
add_executable(${TARGET} retrieval.cpp) | ||
install(TARGETS ${TARGET} RUNTIME) | ||
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | ||
target_compile_features(${TARGET} PRIVATE cxx_std_11) |
This file contains hidden or 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,69 @@ | ||
# llama.cpp/examples/retrieval | ||
|
||
Demonstration of simple retrieval technique based on cosine similarity | ||
|
||
More info: | ||
https://github.com/ggerganov/llama.cpp/pull/6193 | ||
|
||
### How to use | ||
|
||
`retieval.cpp` has parameters of its own: | ||
- `--context-file`: file to be embedded - state this option multiple times to embed multiple files | ||
- `--chunk-size`: minimum size of each text chunk to be embedded | ||
- `--chunk-separator`: STRING to divide chunks by. newline by default | ||
|
||
`retrieval` example can be tested as follows: | ||
|
||
```bash | ||
make -j && ./retrieval --model ./models/bge-base-en-v1.5-f16.gguf --top-k 3 --context-file README.md --context-file License --chunk-size 100 --chunk-separator . | ||
``` | ||
|
||
This chunks and embeds all given files and starts a loop requesting query inputs: | ||
|
||
``` | ||
Enter query: | ||
``` | ||
|
||
On each query input, top k chunks are shown along with file name, chunk position within file and original text: | ||
|
||
``` | ||
Enter query: describe the mit license | ||
batch_decode: n_tokens = 6, n_seq = 1 | ||
Top 3 similar chunks: | ||
filename: README.md | ||
filepos: 119 | ||
similarity: 0.762334 | ||
textdata: | ||
png) | ||
|
||
[](https://opensource.org/licenses/MIT) | ||
|
||
[Roadmap](https://github. | ||
-------------------- | ||
filename: License | ||
filepos: 0 | ||
similarity: 0.725146 | ||
textdata: | ||
MIT License | ||
|
||
Copyright (c) 2023 Georgi Gerganov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
-------------------- | ||
filename: README.md | ||
filepos: 9178 | ||
similarity: 0.621722 | ||
textdata: | ||
com/cztomsik/ava) (MIT) | ||
- [ptsochantaris/emeltal](https://github.com/ptsochantaris/emeltal) | ||
- [pythops/tenere](https://github. | ||
-------------------- | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.