You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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]>
Copy file name to clipboardExpand all lines: docs/config/models.md
+32-3Lines changed: 32 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,38 @@ GraphRAG was built and tested using OpenAI models, so this is the default model
8
8
9
9
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.
10
10
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
+
11
40
## Model Selection Considerations
12
41
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.
14
43
15
44
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.
16
45
@@ -58,11 +87,11 @@ Another option would be to avoid using a language model at all for the graph ext
58
87
59
88
## Using Non-OpenAI Models
60
89
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:
62
91
63
92
### Proxy APIs
64
93
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.
Copy file name to clipboardExpand all lines: docs/config/yaml.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,8 @@ models:
41
41
42
42
- `api_key` **str** - The OpenAI API key to use.
43
43
- `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.
45
46
- `model`**str** - The model name.
46
47
- `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).
Copy file name to clipboardExpand all lines: docs/get_started.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Getting Started
2
2
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.
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:
40
42
41
43
```sh
42
-
graphrag init --root ./ragtest
44
+
graphrag init --root ./christmas
43
45
```
44
46
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.
46
48
47
49
-`.env` contains the environment variables required to run the GraphRAG pipeline. If you inspect the file, you'll see a single environment variable defined,
48
50
`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
78
80
Finally we'll run the pipeline!
79
81
80
82
```sh
81
-
graphrag index --root ./ragtest
83
+
graphrag index --root ./christmas
82
84
```
83
85
84
86

85
87
86
88
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.
88
90
89
91
# Using the Query Engine
90
92
@@ -94,7 +96,7 @@ Here is an example using Global search to ask a high-level question:
94
96
95
97
```sh
96
98
graphrag query \
97
-
--root ./ragtest \
99
+
--root ./christmas \
98
100
--method global \
99
101
--query "What are the top themes in this story?"
100
102
```
@@ -103,7 +105,7 @@ Here is an example using Local search to ask a more specific question about a pa
103
105
104
106
```sh
105
107
graphrag query \
106
-
--root ./ragtest \
108
+
--root ./christmas \
107
109
--method local \
108
110
--query "Who is Scrooge and what are his main relationships?"
Copy file name to clipboardExpand all lines: docs/index.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,7 @@ At query time, these structures are used to provide materials for the LLM contex
47
47
-[_Global Search_](query/global_search.md) for reasoning about holistic questions about the corpus by leveraging the community summaries.
48
48
-[_Local Search_](query/local_search.md) for reasoning about specific entities by fanning-out to their neighbors and associated concepts.
49
49
-[_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).
Copy file name to clipboardExpand all lines: docs/index/architecture.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,3 +32,20 @@ The GraphRAG library was designed with LLM interactions in mind, and a common se
32
32
Because of these potential error cases, we've added a cache layer around LLM interactions.
33
33
When completion requests are made using the same input set (prompt and tuning parameters), we return a cached result if one exists.
34
34
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.
Copy file name to clipboardExpand all lines: docs/index/inputs.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,10 @@ All input formats are loaded within GraphRAG and passed to the indexing pipeline
16
16
17
17
Also see the [outputs](outputs.md) documentation for the final documents table schema saved to parquet after pipeline completion.
18
18
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
+
19
23
## Formats
20
24
21
25
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.
0 commit comments