|
| 1 | +# create search application |
| 2 | + |
| 3 | +You can use redis-llm to create a search application which can answer questions based on your private data stored in the vector store. Normally, you need to run the following steps: |
| 4 | + |
| 5 | +- Call LLM.CREATE-LLM to create an LLM model. |
| 6 | +- Call LLM.CREATE-VECTOR-STORE to create a vector store with LLM support. |
| 7 | +- Call LLM.ADD to add your private data to the store. |
| 8 | +- Call LLM.CREATE-SEARCH to create a search application with LLM and vector store. |
| 9 | +- Call LLM.RUN to ask questions on your private data. |
| 10 | + |
| 11 | +I splitted [Redis' commands documentation](https://github.com/redis/redis-doc/tree/master/commands), and [redis-plus-plus (C++ Redis client)'s README.md](https://github.com/sewenew/redis-plus-plus/blob/master/README.md) into segmentations. For each segmentation, I saved it into a file, and called OpenAI embedding API (model: text-embedding-ada-002) to generate their embeddings. These data and embeddings are located at *examples/search-application/embeddings.zip*. You can unzip it to add into vector store. |
| 12 | + |
| 13 | +``` |
| 14 | +unzip embeddings.zip |
| 15 | +``` |
| 16 | + |
| 17 | +``` |
| 18 | +ls embeddings |
| 19 | +data redis-cmds-embedding redis-plus-plus-doc-embeddings |
| 20 | +``` |
| 21 | + |
| 22 | +You can find all segmentation files under *data* directory. *redis-cmds-embedding* and *redis-plus-plus-doc-embeddings* are embeddings files. Each embedding file contains pre-generated embeddings. Each line of the file contains data file name and data embedding, separated with "\t". |
| 23 | + |
| 24 | +You can use *examples/search-application/create-search-app.sh* script to run create LLM model and vector store, add pre-genereated embeddings to the store, and create a search application. The following is the usage: |
| 25 | + |
| 26 | +```Shell |
| 27 | +create-search-app.sh embedding-file data-path store-key llm-key openai-api-key search-key |
| 28 | +``` |
| 29 | + |
| 30 | +- *embedding-file*: Path to embedding file. e.g. examples/search-application/embeddings/redis-plus-plus-doc-embeddings |
| 31 | +- *data-path*: Path to data directory, e.g. examples/search-application/embeddings/data. |
| 32 | +- *store-key*: Redis key for the created vector store. |
| 33 | +- *llm-key*: Redis key for the created LLM model. |
| 34 | +- *openai-api-key*: Your OpenAI API key. |
| 35 | +- *search-key*: Redis key for the created search application. |
| 36 | + |
| 37 | +Ensure you've already installed `redis-cli`, and launched Redis server on localhost with redis-llm module loaded: |
| 38 | + |
| 39 | +``` |
| 40 | +redis-cli module list |
| 41 | +1) 1) "name" |
| 42 | + 2) "LLM" |
| 43 | + 3) "ver" |
| 44 | + 4) (integer) 1 |
| 45 | +``` |
| 46 | + |
| 47 | +## Create a search application to ask question on Redis commands' documentation |
| 48 | + |
| 49 | +Run the following command to load Redis documenation and embeddings: |
| 50 | + |
| 51 | +``` |
| 52 | +cd /path/to/redis-llm/examples/search-application |
| 53 | +
|
| 54 | +sh create-search-app.sh embeddings/redis-cmds-embedding embeddings/data redis-cmd-store openai-model $YOUR-OPENAI-API-KEY redis-cmd-searcher |
| 55 | +``` |
| 56 | + |
| 57 | +Ask questions on how to use Redis commands: |
| 58 | + |
| 59 | +``` |
| 60 | +redis-cli llm.run redis-cmd-searcher 'How to run set command?' |
| 61 | +``` |
| 62 | + |
| 63 | +## Create a search application to ask question on redis-plus-plus' documentation |
| 64 | + |
| 65 | +Run the following command to load redis-plus-plus' documenation and embeddings: |
| 66 | + |
| 67 | +``` |
| 68 | +cd /path/to/redis-llm/examples/search-application |
| 69 | +
|
| 70 | +sh create-search-app.sh embeddings/redis-plus-plus-doc-embeddings embeddings/data redis-plus-plus-doc-store openai-model $YOUR-OPENAI-API-KEY redis-plus-plus-searcher |
| 71 | +``` |
| 72 | + |
| 73 | +Ask questions on redis-plus-plus: |
| 74 | + |
| 75 | +``` |
| 76 | +redis-cli llm.run redis-plus-plus-searcher 'Who is the author of redis-plus-plus?' |
| 77 | +``` |
0 commit comments