Skip to content

Commit 818c3b3

Browse files
Jinyu WangJinyu Wang
authored andcommitted
Initial commit
0 parents  commit 818c3b3

File tree

153 files changed

+12397
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+12397
-0
lines changed

.gitignore

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/
133+
134+
# pytype static type analyzer
135+
.pytype/
136+
137+
# Cython debug symbols
138+
cython_debug/
139+
140+
###################################
141+
## Specific setting for this repo
142+
###################################
143+
.vscode/
144+
env_configs/
145+
data/
146+
logs/
147+
148+
# May enable in the future
149+
notebooks/
150+
test/

CODE_OF_CONDUCT.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Microsoft Open Source Code of Conduct
2+
3+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4+
5+
Resources:
6+
7+
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8+
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9+
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

RAI_TRANSPARENCY.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# PIKE-RAG: Responsible AI FAQ
2+
3+
## What is PIKE-RAG?
4+
5+
PIKE-RAG, or PrIvate KnowledgE and Rationale Augmentation Generation, represents an advanced evolution in AI-assisted content interpretation, tailored for industrial applications requiring private knowledge and domain-specific rationale. Unlike conventional Retrieval-Augmented Generation (RAG) systems which primarily rely on retrieval to inform large language models (LLMs), PIKE-RAG introduces a methodology that integrates private knowledge extraction with the generation of a coherent rationale. This technique enables the LLMs to progressively navigate towards more accurate and contextually relevant responses. By parsing data to create detailed knowledge structures akin to a heterogeneous knowledge graph, and guiding LLMs to construct coherent rationale in a knowledge-aware manner, PIKE-RAG surpasses traditional models by extracting, understanding, linking and applying private knowledge that is not readily accessible through standard retrieval processes.
6+
7+
## What can PIKE-RAG do?
8+
9+
The strength of PIKE-RAG lies in its sophisticated ability to link disparate pieces of information across extensive data sets, thereby facilitating the answering of complex queries that are beyond the reach of typical keyword and vector-based search methods. By constructing a heterogeneous knowledge graph from a user-provided private dataset, PIKE-RAG can adeptly navigate through a sea of information to locate and synthesize content that addresses user questions, even when the answers are scattered across multiple documents. Moreover, PIKE-RAG's advanced functionality enables it to tackle thematic inquiries, such as identifying prevailing motifs or patterns within a dataset. This capacity to handle both specific, cross-referenced questions and broader, thematic ones makes PIKE-RAG a powerful tool for extracting actionable insights from large volumes of data.
10+
11+
## What is/are PIKE-RAG's intended use(s)?
12+
13+
PIKE-RAG is an advanced system crafted to revolutionize how large language models assist in complex industrial tasks. Here are the its intended uses:
14+
15+
- PIKE-RAG is specifically engineered to enhance large language models in sectors where the need for deep, domain-specific knowledge is paramount, and where conventional retrieval-augmented systems fall short. Its intended use is in complex industrial applications where the extraction and application of specialized knowledge are critical for achieving accurate and insightful outcomes. By incorporating private knowledge and constructing coherent rationales, PIKE-RAG is adept at guiding LLMs to provide precise responses tailored to intricate queries.
16+
17+
- Aimed at addressing the multifaceted challenges encountered in industrial environments, PIKE-RAG is poised for deployment in scenarios requiring a high level of logical reasoning and the ability to navigate through specialized corpora. It is ideal for use cases that demand not just information retrieval but also a deep understanding of that information and its application in a logical, reasoned manner. This makes PIKE-RAG particularly valuable for tasks where decision-making is heavily reliant on exclusive, industry-specific insights.
18+
19+
- With a focus on the incremental improvement of RAG systems, PIKE-RAG's deployment strategy is designed to systematically tackle tasks based on their knowledge complexity. This approach ensures that as industrial demands evolve, PIKE-RAG can develop alongside, continuously enhancing the decision-making capabilities of LLMs and maintaining relevance and accuracy in the context of the industry's specific needs.
20+
21+
- PIKE-RAG is structured to operate within the framework of existing industry protocols, but users must ensure that it is used in conjunction with responsible analytic practices. The system is designed to augment, not replace, human expertise, and therefore it is essential for domain experts to critically evaluate and interpret PIKE-RAG's outputs, verifying their validity and applicability to the specific context.
22+
23+
- While PIKE-RAG does not independently collect user data, it functions within the larger ecosystem of data processing and management. Users are advised to be mindful of data privacy concerns and are encouraged to review the privacy policies associated with the large language models and data storage solutions interfacing with PIKE-RAG. It is the responsibility of the user to ensure that the use of PIKE-RAG complies with all relevant data protection regulations and organizational guidelines.
24+
25+
## How was PIKE-RAG evaluated? What metrics are used to measure performance?
26+
27+
PIKE-RAG's performance and utility were rigorously assessed through a comprehensive evaluation strategy that employed multiple metrics to measure different aspects of its capabilities. Here's how PIKE-RAG was evaluated and the metrics used to gauge its performance:
28+
29+
- Accuracy Metrics: One fundamental way PIKE-RAG was evaluated is by its performance on public datasets. Metrics such as Exact Match (EM), F1 score, Precision, Recall, and an automatically LLM-powered Accuracy metric were utilized for datasets that have ground-truth labels. These metrics are critical as they offer an objective measure of PIKE-RAG's ability to provide correct answers. Manual checking over random samples from these testing data underscores the reliability of these metrics.
30+
31+
- Transparency and Rationale Assessment: To evaluate the transparency and reliability of the responses generated by PIKE-RAG, the system's outputs were closely examined in conjunction with the reference corpus they were derived from. This evaluation focused on the coherence and relevance of the rationale embedded within the responses, ensuring that the system's logic is traceable and grounded in the source material.
32+
33+
- Hallucination Rate Measurement: The credibility of the rationales provided in PIKE-RAG's responses was subjected to a meticulous manual review, where each sentence was evaluated to ascertain whether the underlying logic could be sourced to any part of the reference corpus.
34+
35+
- Resilience Testing: PIKE-RAG's robustness against various forms of adversarial attacks was tested, including prompt and data corpus injection attacks. These tests, which encompassed both manual and semi-automated techniques, aimed to probe the system's defenses against user prompt injection attacks ("jailbreaks") and cross prompt injection attacks ("data attacks").
36+
37+
## What are the limitations of PIKE-RAG? How can users minimize the impact of PIKE-RAG’s limitations when using the system?
38+
39+
PIKE-RAG, like any advanced system, comes with certain limitations that users should be aware of in order to effectively utilize the system within its operational boundaries. The open-source version of PIKE-RAG is crafted with a general-purpose approach in mind. As a result, while it outperforms other untrained and unadjusted methods across the datasets being tested, it may not deliver the optimal performance possible within a specific domain. This is because it is not fine-tuned to the unique nuances and specialized requirements that certain domains may present.
40+
41+
Users can mitigate the limitations posed by PIKE-RAG's generalist nature by introducing domain-specific customizations. For instance, when deploying PIKE-RAG in a particular domain, users can enhance performance by tailoring the corpus pre-processing steps to better reflect the domain's specificities, thereby ensuring that the knowledge base PIKE-RAG draws from is highly relevant and fine-tuned. Additionally, during the rationale generation phase, users can incorporate domain-specific demonstrations or templates that guide the system to construct rationales that are more aligned with domain expertise and practices. This bespoke approach can significantly improve the relevance and accuracy of the system's outputs, making them more actionable and trustworthy for domain-specific applications.
42+
43+
By understanding and addressing these limitations through targeted domain-specific adjustments, users can effectively harness the power of PIKE-RAG and reduce the impact of its constraints, thus maximizing the system's utility and performance in specialized contexts.
44+
45+
## What operational factors and settings allow for effective and responsible use of PIKE-RAG?
46+
47+
To ensure effective and responsible use of PIKE-RAG, it is important to consider the following operational factors and settings:
48+
49+
- User Expertise: The system is intended for use by trusted individuals who possess the necessary domain sophistication. These users are expected to have experience in handling intricate information tasks, which is crucial for the proper interpretation and analysis of PIKE-RAG's outputs.
50+
51+
- Human Analysis and Provenance Tracking: While PIKE-RAG is generally robust against injection attacks and is capable of identifying conflicting information sources, it is imperative that human analysts perform a thorough review of the system's responses. Reliable insights are generated when users critically evaluate the provenance of the information and ensure that the inferences made by PIKE-RAG during answer generation align with human judgment and domain-specific knowledge.
52+
53+
- Resilience and Safety Considerations: Although PIKE-RAG has undergone rigorous testing for its resilience to various types of adversarial attacks, there is still the possibility that the LLM configured with PIKE-RAG might produce content that is inappropriate or offensive. This is especially relevant when deploying the system in sensitive contexts. To mitigate such risks, developers must carefully assess the outputs within the context of their specific use case. Implementing additional safeguards is crucial, and these may include using safety classifiers, model-specific safety features, and services like [Azure AI Content Safety](https://azure.microsoft.com/en-us/products/ai-services/ai-content-safety), or developing bespoke solutions that are tailored to the unique requirements of the application.
54+
55+
By acknowledging these operational factors and incorporating the appropriate settings and checks, users can leverage PIKE-RAG in a manner that is both effective and aligned with ethical and responsible AI practices. This careful approach ensures that the system's capabilities are harnessed to their full potential while minimizing the risk of misuse or the propagation of harmful content.

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# PIKE-RAG: PrIvate KnowledgE and Rationale Augmented Generation
2+
3+
## Quick Start
4+
5+
Please set your `PYTHONPATH` before running the scripts:
6+
7+
### Windows
8+
9+
```powershell
10+
$Env:PYTHONPATH=PATH-TO-THIS-REPO
11+
12+
# If you exactly under this repository directory, you can do it by
13+
$Env:PYTHONPATH=$PWD
14+
```
15+
16+
### Linux / Mac OS
17+
18+
```sh
19+
export PYTHONPATH=PATH-TO-THIS-REPO
20+
21+
# If you are exactly under the repository directory, you can do it by
22+
export PYTHONPATH=$PWD
23+
```
24+
25+
## .env File
26+
27+
Please follow below environment configuration variable names to create your *.env* file, we suggest you put it under
28+
`PIKE-RAG/env_configs/` which has already been added to *.gitignore* file:
29+
30+
### For Azure OpenAI Client
31+
32+
```sh
33+
AZURE_OPENAI_ENDPOINT = "YOUR-ENDPOINT(https://xxx.openai.azure.com/)"
34+
OPENAI_API_TYPE = "azure"
35+
OPENAI_API_VERSION = "2023-07-01-preview"
36+
```
37+
38+
*Note that the way to access GPT API with key is disabled in Azure now.*
39+
40+
To access GPT resource from Azure, please remember to login to Azure CLI using your *SC-* account:
41+
42+
```sh
43+
# Install Azure-CLI and other dependencies. Sudo permission is required.
44+
bash scripts/install_az.sh
45+
46+
# Login Azure CLI using device code.
47+
bash scripts/login_az.sh
48+
```
49+
50+
### For Azure Meta LlaMa Client
51+
52+
Since the endpoint and API keys varied among different LlaMa models, you can add multiple
53+
(`llama_endpoint_name`, `llama_key_name`) pairs you want to use into the *.env* file, and specify the names when
54+
initializing `AzureMetaLlamaClient` (you can modify the llm client args in the YAML files). If `null` is set to be the
55+
name, the (`LLAMA_ENDPOINT`, `LLAMA_API_KEY`) would be used as the default environment variable name.
56+
57+
```sh
58+
# Option 1: Set only one pair in one time, update these variables every time you want to change the LlaMa model.
59+
LLAMA_ENDPOINT = "YOUR-LLAMA-ENDPOINT"
60+
LLAMA_API_KEY = "YOUR-API-KEY"
61+
62+
# Option 2: Add multiple pairs into the .env file, for example:
63+
LLAMA3_8B_ENDPOINT = "..."
64+
LLAMA3_8B_API_KEY = "..."
65+
66+
LLAMA3_70B_ENDPOINT = "..."
67+
LLAMA3_70B_API_KEY = "..."
68+
```
69+
70+
#### Ways to Get the Available Azure Meta LLaMa **Endpoints**, **API Keys** and **Model Names**
71+
72+
The way we have implemented the LLaMa model so far involves requesting the deployed model on the GCR server. You can
73+
find the available settings follow the steps below:
74+
75+
1. Open [Azure Machine Learning Studio](https://ml.azure.com/home), sign in may be required;
76+
2. Click *Workspaces* on the left side (expand the menu by clicking the three horizontal lines in the top left corner if
77+
you cannot find it);
78+
3. Choose and click on a valid workspace, e.g., *gcrllm2ws*;
79+
4. Click *Endpoints* on the left side (expand the menu by clicking the three horizontal lines in the top left corner if
80+
you cannot find it), You can find the available model list in this page;
81+
5. Choose and click the model you want to use, e.g., *gcr-llama-3-8b-instruct*:
82+
- **model** name: in tab "Details", scroll to find "Deployment summary", the *Live traffic allocation* string (e.g.,
83+
*meta-llama-3-8b-instruct-4*) is the model name you need to set up in your YAML file;
84+
- **LLAMA_ENDPOINT** & **LLAMA_API_KEY**: can be found in tab "Consume".
85+
86+
#### Handling the Issue "Specified deployment could not be found"
87+
88+
If you get error message "Specified deployment could not be found", it indicates that the GCR team has changed the
89+
server deployment location. In this case, you need to check the available model list in
90+
[Azure Machine Learning Studio](https://ml.azure.com/home) and update the YAML config again.
91+
92+
## Contributing
93+
94+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
95+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
96+
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
97+
98+
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
99+
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
100+
provided by the bot. You will only need to do this once across all repos using our CLA.
101+
102+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
103+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
104+
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
105+
106+
## Trademarks
107+
108+
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
109+
trademarks or logos is subject to and must follow
110+
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
111+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
112+
Any use of third-party trademarks or logos are subject to those third-party's policies.

0 commit comments

Comments
 (0)