Skip to content

Commit fa3fba4

Browse files
authored
Merge pull request #1611 from JoeStech/copilot-extension-lp
RAG Copilot Extension LP
2 parents e8f6cf7 + e05f297 commit fa3fba4

19 files changed

+692
-81
lines changed

assets/contributors.csv

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,82 @@
1-
author,company,github,linkedin,twitter,website
2-
Jason Andrews,Arm,jasonrandrews,jason-andrews-7b05a8,,
3-
Pareena Verma,Arm,pareenaverma,pareena-verma-7853607,,
4-
Ronan Synnott,Arm,,ronansynnott,,
5-
Florent Lebeau,Arm,,,,
6-
Brenda Strech,Remote.It,bstrech,bstrech,@remote_it,www.remote.it
7-
Liliya Wu,Arm,Liliyaw,liliya-wu-8b6227216,,
8-
Julio Suarez,Arm,jsrz,juliosuarez,,
9-
Gabriel Peterson,Arm,gabrieldpeterson,gabrieldpeterson,@gabedpeterson,https://corteximplant.com/@gabe
10-
Christopher Seidl,Arm,,,,
11-
Michael Hall,Arm,,,,
12-
Kasper Mecklenburg,Arm,,,,
13-
Mathias Brossard,Arm,,,,
14-
Julie Gaskin,Arm,,,,
15-
Pranay Bakre,Arm,,,,
16-
Elham Harirpoush,Arm,,,,
17-
Frédéric -lefred- Descamps,OCI,,,,lefred.be
18-
Fr�d�ric -lefred- Descamps,OCI,,,,lefred.be
19-
Kristof Beyls,Arm,,,,
20-
David Spickett,Arm,,,,
21-
Uma Ramalingam,Arm,uma-ramalingam,,,
22-
Konstantinos Margaritis,VectorCamp,markos,konstantinosmargaritis,@freevec1,https://vectorcamp.gr/
23-
Diego Russo,Arm,diegorusso,diegor,diegor,https://www.diegor.it
24-
Jonathan Davies,Arm,,,,
25-
Zhengjun Xing,Arm,,,,
26-
Leandro Nunes,Arm,,,,
27-
Dawid Borycki,,dawidborycki,,,
28-
Ying Yu,Arm,,,,
29-
Bolt Liu,Arm,,,,
30-
Roberto Lopez Mendez,Arm,,,,
31-
Arnaud de Grandmaison,Arm,Arnaud-de-Grandmaison-ARM,arnauddegrandmaison,,
32-
Jose-Emilio Munoz-Lopez,Arm,,,,
33-
James Whitaker,Arm,,,,
34-
Johanna Skinnider,Arm,,,,
35-
Varun Chari,Arm,,,,
36-
Adnan AlSinan,Arm,,,,
37-
Graham Woodward,Arm,,,,
38-
Basma El Gaabouri,Arm,,,,
39-
Gayathri Narayana Yegna Narayanan,Arm,,,,
40-
Alexandros Lamprineas,Arm,,,,
41-
Annie Tallund,Arm,annietllnd,annietallund,,
42-
Cyril Rohr,RunsOn,crohr,cyrilrohr,,
43-
Rin Dobrescu,Arm,,,,
44-
Przemyslaw Wirkus,Arm,PrzemekWirkus,przemyslaw-wirkus-78b73352,,
45-
Nader Zouaoui,Day Devs,nader-zouaoui,nader-zouaoui,@zouaoui_nader,https://daydevs.com/
46-
Alaaeddine Chakroun,Day Devs,Alaaeddine-Chakroun,alaaeddine-chakroun,,https://daydevs.com/
47-
Koki Mitsunami,Arm,,kmitsunami,,
48-
Chen Zhang,Zilliz,,,,
49-
Tianyu Li,Arm,,,,
50-
Georgios Mermigkis,VectorCamp,gMerm,georgios-mermigkis,,https://vectorcamp.gr/
51-
Ben Clark,Arm,,,,
52-
Han Yin,Arm,hanyin-arm,nacosiren,,
53-
Willen Yang,Arm,,,,
54-
Daniel Gubay,,,,,
55-
Paul Howard,,,,,
56-
Iago Calvo Lista,Arm,,,,
57-
Stephen Theobald,Arm,,,,
58-
ThirdAI,,,,,
59-
Preema Merlin Dsouza,,,,,
60-
Dominica Abena O. Amanfo,,,,,
61-
Arm,,,,,
62-
Albin Bernhardsson,,,,,
63-
Przemyslaw Wirkus,,,,,
64-
Zach Lasiuk,,,,,
65-
Daniel Nguyen,,,,,
66-
Joe Stech,Arm,,,,
67-
visualSilicon,,,,,
68-
Konstantinos Margaritis,VectorCamp,,,,
69-
Kieran Hejmadi,,,,,
70-
Alex Su,,,,,
71-
Chaodong Gong,,,,,
72-
Owen Wu,Arm,,,,
73-
Koki Mitsunami,,,,,
74-
Nikhil Gupta,,,,,
75-
Nobel Chowdary Mandepudi,Arm,,,,
76-
Ravi Malhotra,Arm,,,,
77-
Masoud Koleini,,,,,
78-
Na Li,Arm,,,,
79-
Tom Pilar,,,,,
80-
Cyril Rohr,,,,,
81-
Odin Shen,Arm,odincodeshen,odin-shen-lmshen,,
1+
author,company,github,linkedin,twitter,website
2+
Jason Andrews,Arm,jasonrandrews,jason-andrews-7b05a8,,
3+
Pareena Verma,Arm,pareenaverma,pareena-verma-7853607,,
4+
Ronan Synnott,Arm,,ronansynnott,,
5+
Florent Lebeau,Arm,,,,
6+
Brenda Strech,Remote.It,bstrech,bstrech,@remote_it,www.remote.it
7+
Liliya Wu,Arm,Liliyaw,liliya-wu-8b6227216,,
8+
Julio Suarez,Arm,jsrz,juliosuarez,,
9+
Gabriel Peterson,Arm,gabrieldpeterson,gabrieldpeterson,@gabedpeterson,https://corteximplant.com/@gabe
10+
Christopher Seidl,Arm,,,,
11+
Michael Hall,Arm,,,,
12+
Kasper Mecklenburg,Arm,,,,
13+
Mathias Brossard,Arm,,,,
14+
Julie Gaskin,Arm,,,,
15+
Pranay Bakre,Arm,,,,
16+
Elham Harirpoush,Arm,,,,
17+
Frédéric -lefred- Descamps,OCI,,,,lefred.be
18+
Fr�d�ric -lefred- Descamps,OCI,,,,lefred.be
19+
Kristof Beyls,Arm,,,,
20+
David Spickett,Arm,,,,
21+
Uma Ramalingam,Arm,uma-ramalingam,,,
22+
Konstantinos Margaritis,VectorCamp,markos,konstantinosmargaritis,@freevec1,https://vectorcamp.gr/
23+
Diego Russo,Arm,diegorusso,diegor,diegor,https://www.diegor.it
24+
Jonathan Davies,Arm,,,,
25+
Zhengjun Xing,Arm,,,,
26+
Leandro Nunes,Arm,,,,
27+
Dawid Borycki,,dawidborycki,,,
28+
Ying Yu,Arm,,,,
29+
Bolt Liu,Arm,,,,
30+
Roberto Lopez Mendez,Arm,,,,
31+
Arnaud de Grandmaison,Arm,Arnaud-de-Grandmaison-ARM,arnauddegrandmaison,,
32+
Jose-Emilio Munoz-Lopez,Arm,,,,
33+
James Whitaker,Arm,,,,
34+
Johanna Skinnider,Arm,,,,
35+
Varun Chari,Arm,,,,
36+
Adnan AlSinan,Arm,,,,
37+
Graham Woodward,Arm,,,,
38+
Basma El Gaabouri,Arm,,,,
39+
Gayathri Narayana Yegna Narayanan,Arm,,,,
40+
Alexandros Lamprineas,Arm,,,,
41+
Annie Tallund,Arm,annietllnd,annietallund,,
42+
Cyril Rohr,RunsOn,crohr,cyrilrohr,,
43+
Rin Dobrescu,Arm,,,,
44+
Przemyslaw Wirkus,Arm,PrzemekWirkus,przemyslaw-wirkus-78b73352,,
45+
Nader Zouaoui,Day Devs,nader-zouaoui,nader-zouaoui,@zouaoui_nader,https://daydevs.com/
46+
Alaaeddine Chakroun,Day Devs,Alaaeddine-Chakroun,alaaeddine-chakroun,,https://daydevs.com/
47+
Koki Mitsunami,Arm,,kmitsunami,,
48+
Chen Zhang,Zilliz,,,,
49+
Tianyu Li,Arm,,,,
50+
Georgios Mermigkis,VectorCamp,gMerm,georgios-mermigkis,,https://vectorcamp.gr/
51+
Ben Clark,Arm,,,,
52+
Han Yin,Arm,hanyin-arm,nacosiren,,
53+
Willen Yang,Arm,,,,
54+
Daniel Gubay,,,,,
55+
Paul Howard,,,,,
56+
Iago Calvo Lista,Arm,,,,
57+
Stephen Theobald,Arm,,,,
58+
ThirdAI,,,,,
59+
Preema Merlin Dsouza,,,,,
60+
Dominica Abena O. Amanfo,,,,,
61+
Arm,,,,,
62+
Albin Bernhardsson,,,,,
63+
Przemyslaw Wirkus,,,,,
64+
Zach Lasiuk,,,,,
65+
Daniel Nguyen,,,,,
66+
Joe Stech,Arm,,,,
67+
visualSilicon,,,,,
68+
Konstantinos Margaritis,VectorCamp,,,,
69+
Kieran Hejmadi,,,,,
70+
Alex Su,,,,,
71+
Chaodong Gong,,,,,
72+
Owen Wu,Arm,,,,
73+
Koki Mitsunami,,,,,
74+
Nikhil Gupta,,,,,
75+
Nobel Chowdary Mandepudi,Arm,,,,
76+
Ravi Malhotra,Arm,,,,
77+
Masoud Koleini,,,,,
78+
Na Li,Arm,,,,
79+
Tom Pilar,,,,,
80+
Cyril Rohr,,,,,
81+
Odin Shen,Arm,odincodeshen,odin-shen-lmshen,,
82+
Avin Zarlez,Arm,AvinZarlez,avinzarlez,,https://www.avinzarlez.com/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: RAG Overview
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## What is a RAG system?
10+
11+
RAG stands for "Retrieval Augmented Generation". It describes an AI framework that combines information retrieval with text generation to improve the quality and accuracy of AI-generated content.
12+
13+
The basic flow of a RAG system looks like this:
14+
15+
1. Retrieval: The system searches a knowledge base, usually using some combination of vector and/or text search.
16+
2. Augmentation: The retrieved information is then provided as context to a generative AI model to provide additional context for the user's query.
17+
3. The AI model uses both the retrieved knowledge and its internal understanding to generate a more useful response to the user.
18+
19+
The benefits of a RAG system revolve around improved factual accuracy of responses. It also allows a system to understand more up-to-date information, since you can add additional knowledge to the knowledge base much more easily than you could retrain the model.
20+
21+
Most importantly, RAG lets you provide reference links to the user, showing the user where the system is getting its information.
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
title: Vector Database
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## What is a Vector Database?
10+
11+
A vector database is a specialized database designed to store and query vector representations of data. They are a crucial component of many AI applications. But what exactly are they, and how do they work?
12+
13+
Traditional databases store data in tables or objects with defined attributes. However, they struggle to recognize similarities between data points that aren't explicitly defined.
14+
15+
Vector databases, on the other hand, are designed to store a large numbers of vectors (arrays of numbers), and provide algorithms to be able to search through those stored vectors. That makes it much easier to identify similarities by comparing the vector locations in N dimensional space. This is typically done using distance metrics like cosine similarity or Euclidean distance.
16+
17+
How can we convert complex ideas, like the semantic meaning of a series of words, into a series of of number based vectors? We do so using a process called embedding.
18+
19+
### Embeddings
20+
21+
Embeddings are vectors generated through an AI model. We can convert collections of "tokens" (word fragments) into a point in N dimensional space.
22+
23+
Then for any given vector (like the embedding of a question asked by a user) we can query our vector database to find embedded data that is most similar.
24+
25+
For our use case, we want to know which Arm learning path is most relevant to a question a user asks.
26+
27+
First, ahead of time, we have to convert the raw data (Arm learning path content) into more consumable "chunks". In our case, small `yaml` files. Then we run those chunks through our LLM model and embed the content into our FAISS vector database.
28+
29+
### FAISS
30+
31+
FAISS (Facebook AI Similarity Search) is a library developed by Facebook AI Research that is designed to efficiently search for similar vectors in large datasets. FAISS is highly optimized for both memory usage and speed, making it the fastest similarity search algorithm available.
32+
33+
One of the key reasons FAISS is so fast is its implementation of efficient Approximate Nearest Neighbor (ANN) search algorithms. ANN algorithms allow FAISS to quickly find vectors that are close to a given query vector without having to compare it to every single vector in the database. This significantly reduces the search time, especially in large datasets.
34+
35+
Additionally, FAISS performs all searches in-memory, which means that it can leverage the full speed of the system's RAM. This in-memory search capability ensures that the search operations are extremely fast, as they avoid the latency associated with disk I/O operations.
36+
37+
In our application, we can take the input from the user and embed it using the same model we used for our database. We then use FAISS nearest neighbor search to compare the user input to the nearest vectors in the database. We then look at the original chunk files for those closest vectors. Using the data from those `chunk.yaml` files, we can retrieve the Arm resource(s) most relevant for that user's question.
38+
39+
The retrieved resources are then used to augment the context for the LLM, which generates a final response that is both contextually relevant and contains accurate information.
40+
41+
### In Memory Deployment
42+
43+
To ensure that our application scales efficiently, we will copy the FAISS database into every deployment instance. By deploying a static in-memory vector store in each instance, we eliminate the need for a centralized database, which can become a bottleneck as the number of requests increases.
44+
45+
When each instance has its own copy of the FAISS database, it can perform vector searches locally, leveraging the full speed of the system's RAM. This approach ensures that the search operations are extremely fast and reduces the latency associated with network calls to a centralized database.
46+
47+
Moreover, this method enhances the reliability and fault tolerance of our application. If one instance fails, others can continue to operate independently without being affected by the failure. This decentralized approach also simplifies the deployment process, as each instance is self-contained and does not rely on external resources for vector searches.
48+
49+
By copying the FAISS database into every deployment, we achieve a scalable, high-performance solution that can handle a large number of requests efficiently.
50+
51+
## Collecting Data into Chunks
52+
53+
Arm has provided a [companion GitHub repo](https://github.com/ArmDeveloperEcosystem/python-rag-extension/) for this Learning Path that serves as a Python-based Copilot RAG Extension example. In this repo, we have provided scripts to convert an Arm learning path into a series of `chunk.yaml` files for use in our RAG application.
54+
55+
### Clone the GitHub repository
56+
57+
To clone the repo, run
58+
59+
```bash
60+
git clone https://github.com/ArmDeveloperEcosystem/python-rag-extension.git
61+
```
62+
63+
### Chunk Creation Script Set up
64+
65+
Navigate to the `vectorstore` folder in the [python-rag-extension github repo](https://github.com/ArmDeveloperEcosystem/python-rag-extension/) you just cloned.
66+
67+
```bash
68+
cd python-rag-extension/vectorstore
69+
```
70+
71+
It is recommended to use a virtual environment to manage dependencies.
72+
73+
Ensure you have `conda` set up in your development environment. If you aren't sure how, you can follow this [Installation Guide](https://docs.anaconda.com/miniconda/install/).
74+
75+
To create a new conda environment, use the following command:
76+
77+
```sh
78+
conda create --name vectorstore python=3.11
79+
```
80+
81+
Once set up is complete, activate the new environment:
82+
83+
```sh
84+
conda activate vectorstore
85+
```
86+
87+
Install the required packages:
88+
89+
```sh
90+
conda install --file vectorstore-requirements.txt
91+
```
92+
93+
### Generate Chunk Files
94+
95+
To generate chunks, use the following command:
96+
97+
```sh
98+
python chunk_a_learning_path.py --url <LEARNING_PATH_URL>
99+
```
100+
101+
Replace `<LEARNING_PATH_URL>` with the URL of the learning path you want to process. If no URL is provided, the script will default to a [known learning path URL](https://learn.arm.com/learning-paths/cross-platform/kleidiai-explainer).
102+
103+
The script will process the specified learning path and save the chunks as YAML files in a `./chunks/` directory.
104+
105+
## Combine Chunks into FAISS index
106+
107+
Once you have a `./chunks/` directory full of yaml files, we now need to use FAISS to create our vector database.
108+
109+
### OpenAI Key and Endpoint
110+
111+
Ensure your local environment has your `AZURE_OPENAI_KEY` and `AZURE_OPENAI_ENDPOINT` set.
112+
113+
#### If needed, generate Azure OpenAI keys and deployment
114+
115+
1. **Create an OpenAI Resource**:
116+
- Go to the [Azure Portal](https://portal.azure.com/).
117+
- Click on "Create a resource".
118+
- Search for "OpenAI" and select "Azure OpenAI Service".
119+
- Click "Create".
120+
121+
1. **Configure the OpenAI Resource**:
122+
- Fill in the required details such as Subscription, Resource Group, Region, and Name.
123+
- Click "Review + create" and then "Create" to deploy the resource.
124+
125+
1. **Generate API Key and Endpoint**:
126+
- Once the resource is created, navigate to the resource page.
127+
- Under the "Resource Management->Keys and Endpoint" section, you will find the key and endpoint values.
128+
- Copy these values and set them in your local environment.
129+
130+
```sh
131+
export AZURE_OPENAI_KEY="<your_openai_key>"
132+
export AZURE_OPENAI_ENDPOINT="https://<your_openai_endpoint>.openai.azure.com/"
133+
```
134+
135+
You now have the necessary keys to use Azure OpenAI in your application.
136+
137+
1. **Deploy text-embedding-ada-002 model**
138+
- Go inside Azure AI Foundry for your new deployment
139+
- Under "Deployments", ensure you have a deployment for "text-embedding-ada-002"
140+
141+
### Generate Vector Database Files
142+
143+
Run the python script to create the FAISS index `.bin` and `.json` files.
144+
145+
**NOTE:** This assumes the chunk files are located in a `chunks` subfolder, as they should automatically be.
146+
147+
```bash
148+
python local_vectorstore_creation.py
149+
```
150+
151+
Copy the generated `bin` and `json` files to the root directory of your Flask application.
152+
153+
They should be in the `vectorstore/chunks` folder. Since you are likely still in the `vectorstore` folder, run this command to copy:
154+
155+
```bash
156+
cp chunks/faiss_index.bin ../
157+
cp chunks/metadata.json ../
158+
```
159+
160+
Your vector database is now ready for your flask application.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Create GitHub Application
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
Now we need to create a Copilot extension on GitHub to connect to our deployed application.
10+
11+
## Create a GitHub app
12+
13+
> For the most up to date instructions, follow the [official documentation for creating a GitHub App for Copilot Extension](https://docs.github.com/en/copilot/building-copilot-extensions/creating-a-copilot-extension/creating-a-github-app-for-your-copilot-extension#creating-a-github-app).
14+
15+
On any page of [GitHub](https://github.com/), click your profile picture and go to Settings. Scroll down to developer settings, and go to [create a GitHub App](https://github.com/settings/apps).
16+
17+
![Create GitHub Application screen](images/githubapp-create.png)
18+
19+
Your GitHub App must have:
20+
- A name
21+
- A homepage URL
22+
- Make sure Webhook -> Active is deselected
23+
24+
![GitHub App name and URL](images/githubapp-name.png)
25+
![Webhook deselected](images/githubapp-deselected.png)
26+
27+
The rest can be the default values.
28+
29+
Scroll to the bottom and click "Create GitHub App"
30+
31+
## Get Client ID and Secret
32+
33+
After you create your app, open it up. You will see listed your Client ID under General -> About.
34+
35+
![Client ID and Secret](images/githubapp-clientid.png)
36+
37+
Under that is **Client Secrets**, click "Generate a new client secret" and save the value. Make sure you copy it before it goes away, you will need it for the next step as part of the flask application.
38+
39+
## Install Application
40+
41+
Click **Install App** in the sidebar, then install your app onto your account.
42+
43+
![Install](images/githubapp-install.png)

0 commit comments

Comments
 (0)