437 lines
19 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Get Started</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
<link href="https://unpkg.com/prismjs@1.20.0/themes/prism-okaidia.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Primer/19.1.1/tooltips.min.css" crossorigin="anonymous" referrerpolicy="no-referrer">
<style>
html {
padding: 0;
margin: 0;
}
body{
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 0;
margin: 0;
}
footer{
width: 100%;
height: 32px;
font-size: 12px;
display: flex;
flex-direction: row;
justify-content: center;
gap: 18px;
align-items: center;
color: #5d5d5d;
background: #e9eaeb;
border-top: 1px solid #c4c5c6;
}
#cookiesManager{
cursor: pointer;
color: #485fc7;
}
.page-content {
display: flex;
flex-direction: row;
margin: 0;
padding: 0;
overflow: scroll;
padding: 0;
margin: 0;
}
header {
background-color: lightgrey;
height: 2%;
padding: 10px;
}
nav {
padding: 1em;
min-width: 200px;
}
main {
flex: 1;
padding: 0 5em 0 5em;
}
.logotitle {
font-size: 1.5em;
font-weight: bold;
margin: 5px;
}
.number {
all: unset;
}
.tag.token {
all: unset;
}
main ul {
list-style-type: disc;
padding-left: 30px;
margin-top: 10px;
}
h1 {
font-size: 2rem;
margin-top: 10px;
}
h2 {
font-size: 1.5rem;
margin-top: 10px;
font-weight: 500;
}
h3 {
font-size: 1rem;
margin-top: 10px;
font-weight: 500;
}
p {
margin-top: 10px;
}
/* Accessibility styling */
a {
color: #485fc7;
text-decoration: underline;
}
.menu-list a {
text-decoration: none;
}
.token.comment, .token.prolog, .token.doctype, .token.cdata {
color: #8093a5;
}
.token.property, .token.tag, .token.constant, .token.symbol, .token.deleted {
color: #ff36ab;
}
</style>
<script type="module" async="">import mermaid from "https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs";document.addEventListener('DOMContentLoaded', mermaid.initialize({"loadOnSave":true}));</script>
<script>function showTooltip(o,e){o.trigger.className.includes("tooltipped")||(o.trigger.children[0].className="tooltipped tooltipped-s",o.trigger.children[0].ariaLabel=e)}window.addEventListener("load",()=>{var o=new ClipboardJS(".code-copy");o.on("success",o=>showTooltip(o,"Copied!")),o.on("error",o=>showTooltip(o,"Failed..."))});</script>
<script async="" src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js"></script>
<script src="https://wcpstatic.microsoft.com/mscc/lib/v2/wcp-consent.js" type="text/javascript"></script>
<script>
function onConsentChanged(categoryPreferences) {
console.log("onConsentChanged", categoryPreferences);
}
var siteConsent
function initialize(){
var currentYear = new Date().getFullYear()
document.getElementById("copyright").innerHTML = `©️ ${currentYear} Microsoft`;
window.WcpConsent && WcpConsent.init("en-US", "cookie-banner", function (err, _siteConsent) {
if (!err) {
siteConsent = _siteConsent; //siteConsent is used to get the current consent
} else {
console.log("Error initializing WcpConsent: "+ err);
}
}, onConsentChanged, WcpConsent.themes.light);
}
addEventListener("DOMContentLoaded", initialize)
addEventListener("DOMContentLoaded", checkCookieManager)
function checkCookieManager(){
if(siteConsent.isConsentRequired){
document.getElementById("cookiesManager").style.display = 'block';
document.getElementById("divider").style.display = 'block';
}
else{
document.getElementById("cookiesManager").style.display = 'none';
document.getElementById("divider").style.display = 'none';
}
}
function manageConsent() {
if(siteConsent.isConsentRequired){
siteConsent.manageConsent();
}
}
</script>
</head>
<body>
<header>
<div id="cookie-banner"></div>
<a href="/"><span class="logotitle">GraphRAG</span></a>
</header>
<div class="page-content">
<!-- Sidebar -->
<aside class="menu">
<ul class="menu-list">
<li>
<a href="/">Welcome</a>
</li>
<!-- Get Started Links -->
<li>
<a href="/posts/get_started/" class="is-active" aria-current="page">Get Started</a>
<a href="/posts/developing/">Developing</a>
</li>
<!-- Indexing Links -->
<li>
<a href="/posts/index/overview/">Indexing</a>
<ul><li>
<a href="/posts/index/0-architecture/">Architecture</a>
</li><li>
<a href="/posts/index/1-default_dataflow/">Dataflow</a>
</li><li>
<a href="/posts/index/2-cli/">CLI</a>
</li><li>
<a href="/posts/config/overview/">Configuration</a>
<ul>
<li>
<a href="/posts/config/init">Init command</a>
</li>
<li>
<a href="/posts/config/env_vars">Using Env Vars</a>
</li>
<li>
<a href="/posts/config/json_yaml">Using JSON or YAML</a>
</li>
<li>
<a href="/posts/config/custom">Fully Custom</a>
</li>
<li>
<a href="/posts/config/template">Template</a>
</li>
</ul>
</li>
<li>
<a href="/posts/prompt_tuning/overview/">Prompt Tuning</a>
<ul>
<li>
<a href="/posts/prompt_tuning/auto_prompt_tuning/">Automatic Templating</a>
</li>
<li>
<a href="/posts/prompt_tuning/manual_prompt_tuning/">Manual Prompt Tuning</a>
</li>
</ul>
</li>
</ul>
</li>
<!-- Query Links -->
<li>
<a href="/posts/query/overview/">Query</a>
<ul><li>
<a href="/posts/query/1-local_search/">Local Search</a>
</li><li>
<a href="/posts/query/2-question_generation/">Question Generation</a>
</li><li>
<a href="/posts/query/0-global_search/">Global Search</a>
</li><li>
<a href="/posts/query/3-cli/">CLI</a>
</li><li>
<a href="/posts/query/notebooks/overview/">Notebooks</a>
<ul>
<li>
<a href="/posts/query/notebooks/global_search_nb">Global Search</a>
</li>
<li>
<a href="/posts/query/notebooks/local_search_nb">Local Search</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</aside>
<!-- Main Content -->
<main>
<h1>Get Started</h1>
<h2>Requirements</h2>
<p><a href="https://www.python.org/downloads/">Python 3.10-3.12</a></p>
<p>To get started with the GraphRAG system, you have a few options:</p>
<p>👉 <a href="https://github.com/Azure-Samples/graphrag-accelerator">Use the GraphRAG Accelerator solution</a> <br>
👉 <a href="https://pypi.org/project/graphrag/">Install from pypi</a>. <br>
👉 <a href="/posts/developing">Use it from source</a><br></p>
<h2>Quickstart</h2>
<p>To get started with the GraphRAG system we recommend trying the <a href="https://github.com/Azure-Samples/graphrag-accelerator">Solution Accelerator</a> package. This provides a user-friendly end-to-end experience with Azure resources.</p>
<h1>Top-Level Modules</h1>
<p><a href="/posts/index/overview">Indexing Pipeline Overview</a><br>
<a href="/posts/query/overview">Query Engine Overview</a></p>
<h1>Overview</h1>
<p>The following is a simple end-to-end example for using the GraphRAG system.
It shows how to use the system to index some text, and then use the indexed data to answer questions about the documents.</p>
<h1>Install GraphRAG</h1>
<div style="position: relative">
<pre class="language-bash"><code id="code-33" class="language-bash">pip <span class="token function">install</span> graphrag</code></pre>
<button class="code-copy " data-clipboard-target="#code-33" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<h1>Running the Indexer</h1>
<p>Now we need to set up a data project and some initial configuration. Let's set that up. We're using the <a href="/posts/config/overview/">default configuration mode</a>, which you can customize as needed using a <a href="/posts/config/json_yaml/">config file</a>, which we recommend, or <a href="/posts/config/env_vars/">environment variables</a>.</p>
<p>First let's get a sample dataset ready:</p>
<div style="position: relative">
<pre class="language-sh"><code id="code-43" class="language-sh"><span class="token function">mkdir</span> <span class="token parameter variable">-p</span> ./ragtest/input</code></pre>
<button class="code-copy " data-clipboard-target="#code-43" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<p>Now let's get a copy of A Christmas Carol by Charles Dickens from a trusted source</p>
<div style="position: relative">
<pre class="language-sh"><code id="code-47" class="language-sh"><span class="token function">curl</span> https://www.gutenberg.org/cache/epub/24022/pg24022.txt <span class="token operator">></span> ./ragtest/input/book.txt</code></pre>
<button class="code-copy " data-clipboard-target="#code-47" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<p>Next we'll inject some required config variables:</p>
<h2>Set Up Your Workspace Variables</h2>
<p>First let's make sure to setup the required environment variables. For details on these environment variables, and what environment variables are available, see the <a href="/posts/config/overview/">variables documentation</a>.</p>
<p>To initialize your workspace, let's first run the <code>graphrag.index --init</code> command.
Since we have already configured a directory named .ragtest` in the previous step, we can run the following command:</p>
<div style="position: relative">
<pre class="language-sh"><code id="code-60" class="language-sh">python <span class="token parameter variable">-m</span> graphrag.index <span class="token parameter variable">--init</span> <span class="token parameter variable">--root</span> ./ragtest</code></pre>
<button class="code-copy " data-clipboard-target="#code-60" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<p>This will create two files: <code>.env</code> and <code>settings.yaml</code> in the <code>./ragtest</code> directory.</p>
<ul>
<li><code>.env</code> contains the environment variables required to run the GraphRAG pipeline. If you inspect the file, you'll see a single environment variable defined,
<code>GRAPHRAG_API_KEY=&lt;API_KEY&gt;</code>. This is the API key for the OpenAI API or Azure OpenAI endpoint. You can replace this with your own API key.</li>
<li><code>settings.yaml</code> contains the settings for the pipeline. You can modify this file to change the settings for the pipeline.
<br></li>
</ul>
<h4><ins>OpenAI and Azure OpenAI</ins></h4>
<p>To run in OpenAI mode, just make sure to update the value of <code>GRAPHRAG_API_KEY</code> in the <code>.env</code> file with your OpenAI API key.</p>
<h4><ins>Azure OpenAI</ins></h4>
<p>In addition, Azure OpenAI users should set the following variables in the settings.yaml file. To find the appropriate sections, just search for the <code>llm:</code> configuration, you should see two sections, one for the chat endpoint and one for the embeddings endpoint. Here is an example of how to configure the chat endpoint:</p>
<div style="position: relative">
<pre class="language-yaml"><code id="code-88" class="language-yaml"><span class="token key atrule">type</span><span class="token punctuation">:</span> azure_openai_chat <span class="token comment"># Or azure_openai_embedding for embeddings</span>
<span class="token key atrule">api_base</span><span class="token punctuation">:</span> https<span class="token punctuation">:</span>//&lt;instance<span class="token punctuation">></span>.openai.azure.com
<span class="token key atrule">api_version</span><span class="token punctuation">:</span> 2024<span class="token punctuation">-</span>02<span class="token punctuation">-</span>15<span class="token punctuation">-</span>preview <span class="token comment"># You can customize this for other versions</span>
<span class="token key atrule">deployment_name</span><span class="token punctuation">:</span> &lt;azure_model_deployment_name<span class="token punctuation">></span></code></pre>
<button class="code-copy " data-clipboard-target="#code-88" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<ul>
<li>For more details about configuring GraphRAG, see the <a href="/posts/config/overview/">configuration documentation</a>.</li>
<li>To learn more about Initialization, refer to the <a href="/posts/config/init/">Initialization documentation</a>.</li>
<li>For more details about using the CLI, refer to the <a href="/posts/query/3-cli/">CLI documentation</a>.</li>
</ul>
<h2>Running the Indexing pipeline</h2>
<p>Finally we'll run the pipeline!</p>
<div style="position: relative">
<pre class="language-sh"><code id="code-112" class="language-sh">python <span class="token parameter variable">-m</span> graphrag.index <span class="token parameter variable">--root</span> ./ragtest</code></pre>
<button class="code-copy " data-clipboard-target="#code-112" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<p><img src="/img/pipeline-running.png" alt="pipeline executing from the CLI"></p>
<p>This process will take some time to run. This depends on the size of your input data, what model you're using, and the text chunk size being used (these can be configured in your <code>.env</code> file).
Once the pipeline is complete, you should see a new folder called <code>./ragtest/output/&lt;timestamp&gt;/artifacts</code> with a series of parquet files.</p>
<h1>Using the Query Engine</h1>
<h2>Running the Query Engine</h2>
<p>Now let's ask some questions using this dataset.</p>
<p>Here is an example using Global search to ask a high-level question:</p>
<div style="position: relative">
<pre class="language-sh"><code id="code-131" class="language-sh">python <span class="token parameter variable">-m</span> graphrag.query <span class="token punctuation">\</span>
<span class="token parameter variable">--root</span> ./ragtest <span class="token punctuation">\</span>
<span class="token parameter variable">--method</span> global <span class="token punctuation">\</span>
<span class="token string">"What are the top themes in this story?"</span></code></pre>
<button class="code-copy " data-clipboard-target="#code-131" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<p>Here is an example using Local search to ask a more specific question about a particular character:</p>
<div style="position: relative">
<pre class="language-sh"><code id="code-135" class="language-sh">python <span class="token parameter variable">-m</span> graphrag.query <span class="token punctuation">\</span>
<span class="token parameter variable">--root</span> ./ragtest <span class="token punctuation">\</span>
<span class="token parameter variable">--method</span> <span class="token builtin class-name">local</span> <span class="token punctuation">\</span>
<span class="token string">"Who is Scrooge, and what are his main relationships?"</span></code></pre>
<button class="code-copy " data-clipboard-target="#code-135" style="position: absolute; top: 7.5px; right: 6px; padding-top: 3px; cursor: pointer; outline: none; opacity: 0.8;" title="Copy">
<span style="display:inline-block;background:url(https://api.iconify.design/mdi/content-copy.svg) no-repeat center center / contain;width: 16px; height: 16px;" class=""></span>
</button>
</div>
<p>Please refer to <a href="/posts/query/overview">Query Engine</a> docs for detailed information about how to leverage our Local and Global search mechanisms for extracting meaningful insights from data after the Indexer has wrapped up execution.</p>
</main>
</div>
<footer>
<a href="https://go.microsoft.com/fwlink/?LinkId=521839">Privacy</a>
|
<a href="https://go.microsoft.com/fwlink/?LinkId=2259814">Consumer Health Privacy</a>
|
<span id="cookiesManager" onClick="manageConsent();">Cookies</span>
<span id="divider">|</span>
<a href="https://go.microsoft.com/fwlink/?LinkID=206977">Terms of Use</a>
|
<a href="https://www.microsoft.com/trademarks">Trademarks</a>
|
<a href="https://www.microsoft.com" id="copyright"></a>
|
<a href="https://github.com/microsoft/graphrag">GitHub</a>
|
<a href="https://github.com/Azure-Samples/graphrag-accelerator">Solution Accelerator</a>
</footer>
</body>
</html>