Skip to content

Commit 7f996cf

Browse files
natoversedworthen
andauthored
Docs/2.6.0 (#2070)
* Add basic search to overview * Add info on input documents DataFrame * Add info on factories to docs * Add consumption warning and switch to "christmas" for folder name * Add logger to factories list * Add litellm docs. (#2058) * Fix version for input docs * Spelling --------- Co-authored-by: Derek Worthen <[email protected]>
1 parent 9bc899f commit 7f996cf

File tree

7 files changed

+71
-16
lines changed

7 files changed

+71
-16
lines changed

docs/config/models.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,38 @@ GraphRAG was built and tested using OpenAI models, so this is the default model
88

99
GraphRAG also utilizes a language model wrapper library used by several projects within our team, called fnllm. fnllm provides two important functions for GraphRAG: rate limiting configuration to help us maximize throughput for large indexing jobs, and robust caching of API calls to minimize consumption on repeated indexes for testing, experimentation, or incremental ingest. fnllm uses the OpenAI Python SDK under the covers, so OpenAI-compliant endpoints are a base requirement out-of-the-box.
1010

11+
Starting with version 2.6.0, GraphRAG supports using [LiteLLM](https://docs.litellm.ai/) instead of fnllm for calling language models. LiteLLM provides support for 100+ models though it is important to note that when choosing a model it must support returning [structured outputs](https://openai.com/index/introducing-structured-outputs-in-the-api/) adhering to a [JSON schema](https://docs.litellm.ai/docs/completion/json_mode).
12+
13+
Example using LiteLLm as the language model tool for GraphRAG:
14+
15+
```yaml
16+
models:
17+
default_chat_model:
18+
type: chat
19+
auth_type: api_key
20+
api_key: ${GEMINI_API_KEY}
21+
model_provider: gemini
22+
model: gemini-2.5-flash-lite
23+
default_embedding_model:
24+
type: embedding
25+
auth_type: api_key
26+
api_key: ${GEMINI_API_KEY}
27+
model_provider: gemini
28+
model: gemini-embedding-001
29+
```
30+
31+
To use LiteLLM one must
32+
33+
- Set `type` to either `chat` or `embedding`.
34+
- Provide a `model_provider`, e.g., `openai`, `azure`, `gemini`, etc.
35+
- Set the `model` to a one supported by the `model_provider`'s API.
36+
- Provide a `deployment_name` if using `azure` as the `model_provider`.
37+
38+
See [Detailed Configuration](yaml.md) for more details on configuration. [View LiteLLm basic usage](https://docs.litellm.ai/docs/#basic-usage) for details on how models are called (The `model_provider` is the portion prior to `/` while the `model` is the portion following the `/`).
39+
1140
## Model Selection Considerations
1241

13-
GraphRAG has been most thoroughly tested with the gpt-4 series of models from OpenAI, including gpt-4 gpt-4-turbo, gpt-4o, and gpt-4o-mini. Our [arXiv paper](https://arxiv.org/abs/2404.16130), for example, performed quality evaluation using gpt-4-turbo.
42+
GraphRAG has been most thoroughly tested with the gpt-4 series of models from OpenAI, including gpt-4 gpt-4-turbo, gpt-4o, and gpt-4o-mini. Our [arXiv paper](https://arxiv.org/abs/2404.16130), for example, performed quality evaluation using gpt-4-turbo. As stated above, non-OpenAI models are now supported with GraphRAG 2.6.0 and onwards through the use of LiteLLM but the suite of gpt-4 series of models from OpenAI remain the most tested and supported suite of models for GraphRAG.
1443

1544
Versions of GraphRAG before 2.2.0 made extensive use of `max_tokens` and `logit_bias` to control generated response length or content. The introduction of the o-series of models added new, non-compatible parameters because these models include a reasoning component that has different consumption patterns and response generation attributes than non-reasoning models. GraphRAG 2.2.0 now supports these models, but there are important differences that need to be understood before you switch.
1645

@@ -58,11 +87,11 @@ Another option would be to avoid using a language model at all for the graph ext
5887

5988
## Using Non-OpenAI Models
6089

61-
As noted above, our primary experience and focus has been on OpenAI models, so this is what is supported out-of-the-box. Many users have requested support for additional model types, but it's out of the scope of our research to handle the many models available today. There are two approaches you can use to connect to a non-OpenAI model:
90+
As shown above, non-OpenAI models may be used via LiteLLM starting with GraphRAG version 2.6.0 but cases may still exist in which some users wish to use models not supported by LiteLLM. There are two approaches one can use to connect to unsupported models:
6291

6392
### Proxy APIs
6493

65-
Many users have used platforms such as [ollama](https://ollama.com/) to proxy the underlying model HTTP calls to a different model provider. This seems to work reasonably well, but we frequently see issues with malformed responses (especially JSON), so if you do this please understand that your model needs to reliably return the specific response formats that GraphRAG expects. If you're having trouble with a model, you may need to try prompting to coax the format, or intercepting the response within your proxy to try and handle malformed responses.
94+
Many users have used platforms such as [ollama](https://ollama.com/) and [LiteLLM Proxy Server](https://docs.litellm.ai/docs/simple_proxy) to proxy the underlying model HTTP calls to a different model provider. This seems to work reasonably well, but we frequently see issues with malformed responses (especially JSON), so if you do this please understand that your model needs to reliably return the specific response formats that GraphRAG expects. If you're having trouble with a model, you may need to try prompting to coax the format, or intercepting the response within your proxy to try and handle malformed responses.
6695

6796
### Model Protocol
6897

docs/config/yaml.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ models:
4141
4242
- `api_key` **str** - The OpenAI API key to use.
4343
- `auth_type` **api_key|azure_managed_identity** - Indicate how you want to authenticate requests.
44-
- `type` **openai_chat|azure_openai_chat|openai_embedding|azure_openai_embedding|mock_chat|mock_embeddings** - The type of LLM to use.
44+
- `type` **chat**|**embedding**|**openai_chat|azure_openai_chat|openai_embedding|azure_openai_embedding|mock_chat|mock_embeddings** - The type of LLM to use.
45+
- `model_provider` **str|None** - The model provider to use, e.g., openai, azure, anthropic, etc. Required when `type == chat|embedding`. When `type == chat|embedding`, [LiteLLM](https://docs.litellm.ai/) is used under the hood which has support for calling 100+ models. [View LiteLLm basic usage](https://docs.litellm.ai/docs/#basic-usage) for details on how models are called (The `model_provider` is the portion prior to `/` while the `model` is the portion following the `/`). [View Language Model Selection](models.md) for more details and examples on using LiteLLM.
4546
- `model` **str** - The model name.
4647
- `encoding_model` **str** - The text encoding model to use. Default is to use the encoding model aligned with the language model (i.e., it is retrieved from tiktoken if unset).
4748
- `api_base` **str** - The API base url to use.

docs/get_started.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Getting Started
22

3+
⚠️ GraphRAG can consume a lot of LLM resources! We strongly recommend starting with the tutorial dataset here until you understand how the system works, and consider experimenting with fast/inexpensive models first before committing to a big indexing job.
4+
35
## Requirements
46

57
[Python 3.10-3.12](https://www.python.org/downloads/)
@@ -24,25 +26,25 @@ pip install graphrag
2426
We need to set up a data project and some initial configuration. First let's get a sample dataset ready:
2527

2628
```sh
27-
mkdir -p ./ragtest/input
29+
mkdir -p ./christmas/input
2830
```
2931

3032
Get a copy of A Christmas Carol by Charles Dickens from a trusted source:
3133

3234
```sh
33-
curl https://www.gutenberg.org/cache/epub/24022/pg24022.txt -o ./ragtest/input/book.txt
35+
curl https://www.gutenberg.org/cache/epub/24022/pg24022.txt -o ./christmas/input/book.txt
3436
```
3537

3638
## Set Up Your Workspace Variables
3739

3840
To initialize your workspace, first run the `graphrag init` command.
39-
Since we have already configured a directory named `./ragtest` in the previous step, run the following command:
41+
Since we have already configured a directory named `./christmas` in the previous step, run the following command:
4042

4143
```sh
42-
graphrag init --root ./ragtest
44+
graphrag init --root ./christmas
4345
```
4446

45-
This will create two files: `.env` and `settings.yaml` in the `./ragtest` directory.
47+
This will create two files: `.env` and `settings.yaml` in the `./christmas` directory.
4648

4749
- `.env` contains the environment variables required to run the GraphRAG pipeline. If you inspect the file, you'll see a single environment variable defined,
4850
`GRAPHRAG_API_KEY=<API_KEY>`. Replace `<API_KEY>` with your own OpenAI or Azure API key.
@@ -78,13 +80,13 @@ You will also need to login with [az login](https://learn.microsoft.com/en-us/cl
7880
Finally we'll run the pipeline!
7981
8082
```sh
81-
graphrag index --root ./ragtest
83+
graphrag index --root ./christmas
8284
```
8385

8486
![pipeline executing from the CLI](img/pipeline-running.png)
8587

8688
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 `settings.yaml` file).
87-
Once the pipeline is complete, you should see a new folder called `./ragtest/output` with a series of parquet files.
89+
Once the pipeline is complete, you should see a new folder called `./christmas/output` with a series of parquet files.
8890

8991
# Using the Query Engine
9092

@@ -94,7 +96,7 @@ Here is an example using Global search to ask a high-level question:
9496

9597
```sh
9698
graphrag query \
97-
--root ./ragtest \
99+
--root ./christmas \
98100
--method global \
99101
--query "What are the top themes in this story?"
100102
```
@@ -103,7 +105,7 @@ Here is an example using Local search to ask a more specific question about a pa
103105

104106
```sh
105107
graphrag query \
106-
--root ./ragtest \
108+
--root ./christmas \
107109
--method local \
108110
--query "Who is Scrooge and what are his main relationships?"
109111
```

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ At query time, these structures are used to provide materials for the LLM contex
4747
- [_Global Search_](query/global_search.md) for reasoning about holistic questions about the corpus by leveraging the community summaries.
4848
- [_Local Search_](query/local_search.md) for reasoning about specific entities by fanning-out to their neighbors and associated concepts.
4949
- [_DRIFT Search_](query/drift_search.md) for reasoning about specific entities by fanning-out to their neighbors and associated concepts, but with the added context of community information.
50+
- _Basic Search_ for those times when your query is best answered by baseline RAG (standard top _k_ vector search).
5051

5152
### Prompt Tuning
5253

docs/index/architecture.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,20 @@ The GraphRAG library was designed with LLM interactions in mind, and a common se
3232
Because of these potential error cases, we've added a cache layer around LLM interactions.
3333
When completion requests are made using the same input set (prompt and tuning parameters), we return a cached result if one exists.
3434
This allows our indexer to be more resilient to network issues, to act idempotently, and to provide a more efficient end-user experience.
35+
36+
### Providers & Factories
37+
38+
Several subsystems within GraphRAG use a factory pattern to register and retrieve provider implementations. This allows deep customization to support models, storage, and so on that you may use but isn't built directly into GraphRAG.
39+
40+
The following subsystems use a factory pattern that allows you to register your own implementations:
41+
42+
- [language model](https://github.com/microsoft/graphrag/blob/main/graphrag/language_model/factory.py) - implement your own `chat` and `embed` methods to use a model provider of choice beyond the built-in OpenAI/Azure support
43+
- [cache](https://github.com/microsoft/graphrag/blob/main/graphrag/cache/factory.py) - create your own cache storage location in addition to the file, blob, and CosmosDB ones we provide
44+
- [logger](https://github.com/microsoft/graphrag/blob/main/graphrag/logger/factory.py) - create your own log writing location in addition to the built-in file and blob storage
45+
- [storage](https://github.com/microsoft/graphrag/blob/main/graphrag/storage/factory.py) - create your own storage provider (database, etc.) beyond the file, blob, and CosmosDB ones built in
46+
- [vector store](https://github.com/microsoft/graphrag/blob/main/graphrag/vector_stores/factory.py) - implement your own vector store other than the built-in lancedb, Azure AI Search, and CosmosDB ones built in
47+
- [pipeline + workflows](https://github.com/microsoft/graphrag/blob/main/graphrag/index/workflows/factory.py) - implement your own workflow steps with a custom `run_workflow` function, or register an entire pipeline (list of named workflows)
48+
49+
The links for each of these subsystems point to the source code of the factory, which includes registration of the default built-in implementations. In addition, we have a detailed discussion of [language models](../config/models.md), which includes and example of a custom provider, and a [sample notebook](../examples_notebooks/custom_vector_store.ipynb) that demonstrates a custom vector store.
50+
51+
All of these factories allow you to register an impl using any string name you would like, even overriding built-in ones directly.

docs/index/inputs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ All input formats are loaded within GraphRAG and passed to the indexing pipeline
1616

1717
Also see the [outputs](outputs.md) documentation for the final documents table schema saved to parquet after pipeline completion.
1818

19+
## Bring-your-own DataFrame
20+
21+
As of version 2.6.0, GraphRAG's [indexing API method](https://github.com/microsoft/graphrag/blob/main/graphrag/api/index.py) allows you to pass in your own pandas DataFrame and bypass all of the input loading/parsing described in the next section. This is convenient if you have content in a format or storage location we don't support out-of-the-box. __You must ensure that your input DataFrame conforms to the schema described above.__ All of the chunking behavior described later will proceed exactly the same.
22+
1923
## Formats
2024

2125
We support three file formats out-of-the-box. This covers the overwhelming majority of use cases we have encountered. If you have a different format, we recommend writing a script to convert to one of these, which are widely used and supported by many tools and libraries.

mkdocs.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ theme:
2222

2323
nav:
2424
- Home:
25-
- Welcome: index.md
26-
- Getting Started: get_started.md
27-
- Development Guide: developing.md
25+
- Welcome: "index.md"
26+
- Getting Started: "get_started.md"
27+
- Development Guide: "developing.md"
2828
- Indexing:
2929
- Overview: "index/overview.md"
30+
- Architecture: "index/architecture.md"
3031
- Dataflow: "index/default_dataflow.md"
3132
- Methods: "index/methods.md"
3233
- Inputs: "index/inputs.md"

0 commit comments

Comments
 (0)