|
| 1 | +# nilRAG |
| 2 | + |
| 3 | +Retrieval Augmented Generation (RAG) is a technique that grants large language |
| 4 | +models (LLMs) information retrieval capabilities and context that they might be |
| 5 | +missing. Nillion's RAG (nilRAG) uses [nilAI |
| 6 | +(SecretLLM)](https://docs.nillion.com/build/secretLLM/quickstart), [nilDB |
| 7 | +(SecretVault)](https://docs.nillion.com/build/secret-vault-quickstart), and |
| 8 | +[nilQL](https://docs.nillion.com/build/nilQL). |
| 9 | + |
| 10 | +:::info |
| 11 | +In simple terms, nilRAG allows you to store information in SecretVault and then use it as context when you query SecretLLM! |
| 12 | +::: |
| 13 | + |
| 14 | + |
| 15 | +## Library Overview |
| 16 | +Data owners often possess valuable files that clients wish to query to enhance |
| 17 | +their LLM-based inferences. However, ensuring privacy is a key challenge: data |
| 18 | +owners want to keep their data confidential, and clients are equally concerned |
| 19 | +about safeguarding their queries. nilRAG addresses this challenge by enabling |
| 20 | +secure data sharing and querying. It allows data owners to store their data |
| 21 | +securely in SecretVault while allowing clients to query the data without |
| 22 | +exposing their queries or compromising the data's privacy. The process involves |
| 23 | +leveraging a SecretLLM for secure computation through nilAI. Data owners upload |
| 24 | +their information to SecretVault, while SecretLLM processes client queries and |
| 25 | +retrieves the most relevant results (top-k) without revealing sensitive |
| 26 | +information from either party. |
| 27 | + |
| 28 | + |
| 29 | +Let us deep dive into the entities and their roles in the system. |
| 30 | + |
| 31 | +1. **Data Owners:** Securely upload files to SecretVault. Before sending the |
| 32 | + files to SecretVault, they are processed into multiple chunks of data and |
| 33 | + their corresponding embeddings. The embeddings are used for similarity |
| 34 | + search, while the chunks are used to retrieve the actual uploaded files. Once |
| 35 | + the files are encoded into chunks and embeddings, they are blinded before |
| 36 | + being uploaded to SecretVault, where each chunk and embedding is |
| 37 | + secret-shared. |
| 38 | + |
| 39 | + For instance, a data owner, wishes to upload the following file to SecretVault and later use it to provide context to SecretLLM: |
| 40 | + :::note Employees Example |
| 41 | + ``` |
| 42 | + Kyle Moore works at Jackson, Gray and Lewis as a Economist. Kyle Moore was born on 1915-09-27 and lives at 6206 Caroline Point, Bishopland, MI 34522. |
| 43 | +
|
| 44 | + Charles Anderson works at Evans, Parker and Ramirez as a Surveyor, insurance. Charles Anderson was born on 2016-12-13 and lives at 0527 William Walk Suite 976, Lake Jason, MS 97840. |
| 45 | +
|
| 46 | + Danielle Miller works at Bailey and Sons as a Engineer, mining. Danielle Miller was born on 2007-10-22 and lives at 61586 Michael Greens, New Holly, CO 29872. |
| 47 | + ... |
| 48 | + ``` |
| 49 | + ::: |
| 50 | +
|
| 51 | +
|
| 52 | +2. **Client:** The client submits a query to search against the data owners' |
| 53 | + uploaded files in SecretVault, retrieve the most relevant data, and use the |
| 54 | + top-k results for privacy-preserving inference in SecretLLM. Similar to the |
| 55 | + encoding by data owners, the query is processed into its corresponding |
| 56 | + embeddings. |
| 57 | +
|
| 58 | + Going back to our example, the client can query SecretLLM asking about Danielle: |
| 59 | + :::note Employees Example |
| 60 | + ``` |
| 61 | + Who is Danielle Miller? |
| 62 | + ``` |
| 63 | + ::: |
| 64 | +
|
| 65 | +
|
| 66 | +3. **SecretVault:** SecretVault stores the blinded chunks and embeddings |
| 67 | + provided by data owners. When a client submits a query, SecretVault computes |
| 68 | + the differences between the query's embeddings and each stored embedding in a |
| 69 | + privacy-preserving manner. |
| 70 | +
|
| 71 | +
|
| 72 | +4. **SecretLLM:** SecretLLM connects to SecretVault to fetch the blinded |
| 73 | + differences between the query and the stored embeddings and then compute the |
| 74 | + closest matches. Finally, it uses the top k matches for inference. |
| 75 | +
|
| 76 | + Lastly, the client can query SecretLLM asking about Danielle: |
| 77 | + :::note Employees Example |
| 78 | + ``` |
| 79 | + Danielle Miller is an engineer who works at Bailey and Sons, specializing in mining. She was born on October 22, 2007, and lives at 61586 Michael Greens, New Holly, CO 29872. |
| 80 | + ``` |
| 81 | + ::: |
| 82 | +
|
| 83 | +
|
| 84 | +You can reproduce the example above by following the [README](https://github.com/NillionNetwork/nilrag). |
| 85 | +
|
| 86 | +## Implementation |
| 87 | +
|
| 88 | +nilRAG is not a standalone library available through |
| 89 | +[PyPI](https://pypi.org/project/nilrag) and open-source on |
| 90 | +[GitHub](https://github.com/NillionNetwork/nilrag). Developers can use nilRAG as |
| 91 | +a feature of [SecretLLM](https://docs.nillion.com/build/secretLLM/quickstart) to |
| 92 | +enhance the inference with context that has been uploaded to [SecretVault](https://docs.nillion.com/build/secret-vault). |
| 93 | +
|
0 commit comments