Skip to content

Commit a87167b

Browse files
authored
DOCSP 43493 VSCode Copilot /query functionality (#92)
1 parent 5360f07 commit a87167b

File tree

8 files changed

+363
-1
lines changed

8 files changed

+363
-1
lines changed

snooty.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ toc_landing_pages = [
1010
"/playgrounds",
1111
"/crud-ops",
1212
"/playground-databases",
13-
"/require-playgrounds"
13+
"/require-playgrounds",
14+
"/copilot"
1415
]
1516

1617
[constants]
@@ -40,6 +41,7 @@ cifs = ":abbr:`CIFS (Common Internet File System)`"
4041
cps = ":abbr:`CPS (Cloud Provider Snapshots)`"
4142
cmk = ":abbr:`CMK (customer master key)`"
4243
compass = "MongoDB Compass"
44+
copilot = "MongoDB GitHub Copilot Participant"
4345
data-lakes = "Data Lakes"
4446
data-lake = "Data Lake"
4547
datadog = "`Datadog <https://www.datadoghq.com/>`__"

source/ai-data-usage.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. vscode-ai-data-usage:
2+
3+
=============================
4+
AI and Data Usage Information
5+
=============================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
12+
The |copilot| is powered by Generative AI (Gen AI), and may give
13+
inaccurate responses. See our `Generative AI FAQ
14+
<https://dochub.mongodb.org/core/faq-ai-features>`__ for more
15+
information about Gen AI in MongoDB products.
16+
17+
Third Party Providers
18+
---------------------
19+
20+
The |copilot| is powered by `GitHub Copilot
21+
<https://github.com/features/copilot>`__.
22+
23+
How Your Data is Used
24+
---------------------
25+
26+
When you use the |copilot| , the following information is sent to
27+
MongoDB's backend, the MongoDB Docs Chatbot, and/or the third party AI
28+
provider:
29+
30+
- The full text of your natural language prompt.
31+
- The schema of the collection you are using,
32+
including database name, collection name, field names, and types.
33+
34+
The information that is sent will not be shared with any other third
35+
parties or stored by the AI provider. We do not send database
36+
connection strings, credentials, or rows/documents from your databases.

source/copilot-query.txt

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
.. _vsce-copilot-query:
2+
3+
==============
4+
/query Command
5+
==============
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
The ``/query`` command assists in generating queries from a natural
16+
language against a connected MongoDB cluster. The |copilot| provides
17+
underlying schema information of the relevant collections to GitHub
18+
Copilot to generate a response. If you do not specify a collection in
19+
your prompt, the chat prompts you to select a relevant collection.
20+
21+
When the LLM generates a query, you can open the query in a playground
22+
file or run the query directly in your collection.
23+
24+
Examples
25+
~~~~~~~~
26+
27+
Generate a Query
28+
````````````````
29+
30+
Consider the ``users`` collection in the `Mflix Sample Database
31+
<https://www.mongodb.com/docs/atlas/sample-data/sample-mflix/#sample_mflix.users>`__.
32+
Each document in the collection has the following structure:
33+
34+
.. code-block:: javascript
35+
:copyable: false
36+
37+
{
38+
_id: {
39+
"$oid": "59b99db4cfa9a34dcd7885b6"
40+
},
41+
name: "Kayden Washington",
42+
43+
password: "11222021"
44+
}
45+
46+
Once you connect to the deployment that contains the ``users``
47+
collection, you can ask the GitHub Copilot chat to generate a query that
48+
finds the document in the ``users`` collection that has the ``name``
49+
value of ``Kayden Washington``.
50+
51+
.. code-block:: javascript
52+
:copyable: false
53+
54+
@MongoDB /query In the sample_mflix database, find a document in the
55+
users collection with the name of Kayden Washington.
56+
57+
The GitHub Copilot Chat uses the |copilot| to
58+
generate the following query using knowledge of your database schema:
59+
60+
.. code-block:: javascript
61+
62+
use(`sample_mflix`);
63+
db.getCollection('users').findOne({ name: 'Kayden Washington' });
64+
65+
Once the |copilot| generates the query, you can choose to run the query
66+
directly or open the query in a playground.
67+
68+
.. figure:: /images/copilot-query.png
69+
:figwidth: 700px
70+
:alt: Screenshot of copilot generating a query
71+
72+
Build an Aggregation Pipeline
73+
`````````````````````````````
74+
75+
You can also use the |copilot| to build aggregation pipelines. Consider
76+
the ``users`` collection in the `Mflix Sample Database
77+
<https://www.mongodb.com/docs/atlas/sample-data/sample-mflix/#sample_mflix.users>`__.
78+
Each document in the collection has the following structure:
79+
80+
.. code-block:: javascript
81+
:copyable: false
82+
83+
{
84+
_id: {
85+
"$oid": "59b99db4cfa9a34dcd7885b6"
86+
},
87+
name: "Kayden Washington",
88+
89+
password: "11222021"
90+
}
91+
92+
Once you connect to the deployment that contains the ``users``
93+
collection, you can ask the GitHub Copilot chat to generate an aggregation pipeline.
94+
95+
.. code-block:: javascript
96+
:copyable: false
97+
98+
@MongoDB /query Generate an aggregation pipeline on the users
99+
collection that first sorts documents alphabetically by name and then
100+
removes the password field from each document.
101+
102+
The |copilot| generates the following aggregation pipeline:
103+
104+
.. code-block:: javascript
105+
106+
use('sample_mflix');
107+
db.getCollection('users').aggregate([
108+
{ $sort: { name: 1 } },
109+
{ $project: { password: 0 } }
110+
]);
111+
112+
Once the |copilot| generates the query, you can choose to run the pipeline
113+
directly or open the pipeline in a playground.
114+
115+
.. figure:: /images/copilot-agg-pipeline.png
116+
:figwidth: 700px
117+
:alt: Screenshot of copilot generating an aggregation pipeline
118+
119+
You can also iteratively build on your aggregation pipeline:
120+
121+
.. code-block:: javascript
122+
:copyable: false
123+
124+
@MongoDB /query Add a stage to my pipeline that adds a username field
125+
to each document containing the user's email without the
126+
email domain.
127+
128+
The |copilot| returns the following aggregation pipeline:
129+
130+
.. code-block:: javascript
131+
132+
use('sample_mflix');
133+
db.getCollection('users').aggregate([
134+
{ $sort: { name: 1 } },
135+
{ $project: { password: 0 } },
136+
{ $addFields: { username: { $arrayElemAt: [{ $split: ["$email", "@"] }, 0] } } }
137+
]);
138+
139+
.. figure:: /images/copilot-agg-pipeline2.png
140+
:figwidth: 700px
141+
:alt: Screenshot of copilot iteratively building on an aggregation pipeline

source/copilot.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _vsce-copilot:
2+
3+
==================================
4+
|copilot|
5+
==================================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
|vsce-full| includes the |copilot| to assist in using `GitHub Copilot
16+
<https://github.com/features/copilot>`__ with your MongoDB deployments.
17+
Through GitHub Copilot's chat feature, users with |vsce| can interact
18+
with their MongoDB clusters and generate code with MongoDB
19+
domain-specific knowledge on top of GitHub Copilot's LLM. The |copilot|
20+
can also answer questions about your database collection schema and
21+
provide links to specific MongoDB documentation.
22+
23+
The |copilot| includes MongoDB-specific
24+
commands to assist in interacting with your deployment.
25+
26+
Commands
27+
--------
28+
29+
/query
30+
~~~~~~
31+
32+
The ``/query`` command assists in generating queries from a natural
33+
language against a connected MongoDB cluster.
34+
35+
.. toctree::
36+
:titlesonly:
37+
38+
/query </copilot-query>
39+
AI & Data Usage </ai-data-usage>
40+
41+

source/images/copilot-agg-pipeline.png

Lines changed: 47 additions & 0 deletions
Loading

source/images/copilot-agg-pipeline2.png

Lines changed: 47 additions & 0 deletions
Loading

source/images/copilot-query.png

Lines changed: 47 additions & 0 deletions
Loading

source/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Get Started
5656
Connect </connect>
5757
Manage Data </databases-collections>
5858
Explore with Playgrounds </playgrounds>
59+
GitHub Copilot Participant </copilot>
5960
Create an Atlas Cluster with Terraform </create-cluster-terraform>
6061
Reference </reference>
6162
Changelog <https://github.com/mongodb-js/vscode/releases>

0 commit comments

Comments
 (0)