Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/typing with pagination (#1219) #1230

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ py/workspace/
uploads/
env/
**/__pycache__
**/.mypy_cache
**/.pytest_cache
dump/*
.next
node_modules
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ repos:
language: system
types: [python]
pass_filenames: false

- id: mypy
name: mypy
entry: bash -c 'cd py && poetry run mypy .'
language: system
types: [python]
pass_filenames: false
2 changes: 1 addition & 1 deletion docs/api-reference/openapi.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/cookbooks/graphrag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ r2r serve
[kg]
provider = "neo4j"
batch_size = 256
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"

[kg.kg_creation_settings]
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
entity_types = [] # if empty, all entities are extracted
relation_types = [] # if empty, all relations are extracted
max_knowledge_triples = 100
Expand All @@ -47,15 +47,15 @@ kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
generation_config = { model = "gpt-4o-mini" } # and other params, model used for node description and graph clustering
leiden_params = { max_levels = 10 } # more params here: https://neo4j.com/docs/graph-data-science/current/algorithms/leiden/

[kg.kg_search_config]
model = "gpt-4o-mini"
[kg.kg_search_settings]
generation_config = { model = "gpt-4o-mini" }
```
</Accordion>
</Tab>

<Tab title="Local LLMs">
```bash
r2r serve --config-name=local_llm_neo4j_kg
r2r serve --config-name=local_llm
```

### Local LLM Setup (Optional)
Expand All @@ -72,7 +72,7 @@ When running with local RAG, you must have the Triplex model available locally.
```


<Accordion icon="gear" title="Configuration: local_llm_neo4j_kg">
<Accordion icon="gear" title="Configuration: local_llm">
``` toml
[completion]
provider = "litellm"
Expand All @@ -96,9 +96,9 @@ excluded_parsers = [ "gif", "jpeg", "jpg", "png", "svg", "mp3", "mp4" ]

[kg]
provider = "neo4j"
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"

[kg.kg_creation_settings]
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
entity_types = [] # if empty, all entities are extracted
relation_types = [] # if empty, all relations are extracted
max_knowledge_triples = 100
Expand All @@ -111,8 +111,8 @@ kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
generation_config = { model = "ollama/llama3.1" } # and other params, model used for node description and graph clustering
leiden_params = { max_levels = 10 } # more params here: https://neo4j.com/docs/graph-data-science/current/algorithms/leiden/

[kg.kg_search_config]
model = "ollama/llama3.1"
[kg.kg_search_settings]
generation_config = { model = "ollama/llama3.1" }

[database]
provider = "postgres"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ You can configure knowledge graph enrichment in the R2R configuration file. To d
[kg]
provider = "neo4j"
batch_size = 256
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"

[kg.kg_creation_settings]
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
entity_types = [] # if empty, all entities are extracted
relation_types = [] # if empty, all relations are extracted
fragment_merge_count = 4 # number of fragments to merge into a single extraction
Expand All @@ -26,8 +26,8 @@ kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
generation_config = { model = "gpt-4o-mini" } # and other generation params
leiden_params = { max_levels = 10 } # more params in graspologic/partition/leiden.py

[kg.kg_search_config]
model = "gpt-4o-mini"
[kg.kg_search_settings]
generation_config = { model = "gpt-4o-mini" }
```

Next you can do GraphRAG with the knowledge graph. Find out more about GraphRAG in the [GraphRAG Guide](/cookbooks/graphrag).
8 changes: 4 additions & 4 deletions docs/documentation/configuration/knowledge-graph/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
generation_config = { model = "gpt-4o-mini" } # and other generation params below
leiden_params = { max_levels = 10 } # more params in https://neo4j.com/docs/graph-data-science/current/algorithms/leiden/

[kg.kg_search_config]
model = "gpt-4o-mini"
[kg.kg_search_settings]
generation_config = { model = "gpt-4o-mini" }
```


Expand All @@ -47,7 +47,7 @@ Let's break down the knowledge graph configuration options:
- `kg_enrichment_settings`: Similar configuration for the model used in knowledge graph enrichment.
- `generation_config`: Configuration for the model used in knowledge graph enrichment.
- `leiden_params`: Parameters for the Leiden algorithm.
- `kg_search_config`: Similar configuration for the model used in knowledge graph search operations.
- `kg_search_settings`: Similar configuration for the model used in knowledge graph search operations.

### Neo4j Configuration

Expand Down Expand Up @@ -88,7 +88,7 @@ The Neo4jKGProvider supports various operations:

### Customization

You can customize the knowledge graph extraction and search processes by modifying the `kg_extraction_prompt` and adjusting the model configurations in `kg_extraction_config` and `kg_search_config`. Moreover, you can customize the LLM models used in various parts of the knowledge graph creation process. All of these options can be selected at runtime, with the only exception being the specified database provider. For more details, refer to the knowledge graph settings in the [search API](/api-reference/endpoint/search).
You can customize the knowledge graph extraction and search processes by modifying the `kg_extraction_prompt` and adjusting the model configurations in `kg_extraction_settings` and `kg_search_settings`. Moreover, you can customize the LLM models used in various parts of the knowledge graph creation process. All of these options can be selected at runtime, with the only exception being the specified database provider. For more details, refer to the knowledge graph settings in the [search API](/api-reference/endpoint/search).

By leveraging the knowledge graph capabilities, you can enhance R2R's understanding of document relationships and improve the quality of search and retrieval operations.

Expand Down
4 changes: 2 additions & 2 deletions docs/documentation/configuration/postgres.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ password = "your_postgres_password"
host = "your_postgres_host"
port = "your_postgres_port"
db_name = "your_database_name"
your_project_name = "your_project_collection_name"
your_project_name = "your_project_name"
```

2. Alternatively, you can set the following environment variables:
Expand All @@ -46,7 +46,7 @@ export POSTGRES_PASSWORD=your_postgres_password
export POSTGRES_HOST=your_postgres_host
export POSTGRES_PORT=your_postgres_port
export POSTGRES_DBNAME=your_database_name
export POSTGRES_PROJECT_NAME=your_vector_collection_name
export POSTGRES_PROJECT_NAME=your_project_name
```

## Advanced Postgres Features in R2R
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/configuration/rag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ kg_search_settings = {
"use_kg_search": True,
"kg_search_type": "global",
"kg_search_level": None,
"kg_search_generation_config": {
"generation_config": {
"model": "gpt-4",
"temperature": 0.1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ kg_search_settings = {
"use_kg_search": True,
"kg_search_type": "global",
"kg_search_level": None,
"kg_search_generation_config": {
"generation_config": {
"model": "gpt-4",
"temperature": 0.1
},
Expand All @@ -28,7 +28,7 @@ response = client.search("query", kg_search_settings=kg_search_settings)
1. `use_kg_search` (bool): Whether to use knowledge graph search
2. `kg_search_type` (str): Type of knowledge graph search ('global' or 'local')
3. `kg_search_level` (Optional[str]): Level of knowledge graph search
4. `kg_search_generation_config` (Optional[GenerationConfig]): Configuration for knowledge graph search generation
4. `generation_config` (Optional[GenerationConfig]): Configuration for knowledge graph search generation
5. `entity_types` (list): Types of entities to search for
6. `relationships` (list): Types of relationships to search for
7. `max_community_description_length` (int): Maximum length of community descriptions (default: 65536)
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/deep-dive/providers/database.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export POSTGRES_PASSWORD=your_postgres_password
export POSTGRES_HOST=your_postgres_host
export POSTGRES_PORT=your_postgres_port
export POSTGRES_DBNAME=your_database_name
export POSTGRES_PROJECT_NAME=your_collection_name
export POSTGRES_PROJECT_NAME=your_project_name
```
Environment variables take precedence over the config settings in case of conflicts. The R2R Docker includes configuration options that facilitate integration with a combined Postgres+pgvector database setup.

Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/deep-dive/providers/knowledge-graph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ These are located in the `r2r.toml` file, under the `[kg]` section.
[kg]
provider = "neo4j"
batch_size = 256
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
user = "your_neo4j_user"
password = "your_neo4j_password"
url = "your_neo4j_url"
database = "your_neo4j_database"

[kg.kg_creation_settings]
kg_extraction_prompt = "graphrag_triplet_extraction_zero_shot"
entity_types = ["Person", "Organization", "Location"] # if empty, all entities are extracted
relation_types = ["works at", "founded by", "invested in"] # if empty, all relations are extracted
max_knowledge_triples = 100
Expand Down
6 changes: 3 additions & 3 deletions docs/documentation/js-sdk/retrieval.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const searchResponse = await client.search("What was Uber's profit in 2020?");
Level of knowledge graph search.
</ParamField>

<ParamField path="kg_search_generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
<ParamField path="generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
Configuration for knowledge graph search generation.
</ParamField>

Expand Down Expand Up @@ -331,7 +331,7 @@ const ragResponse = await client.rag("What was Uber's profit in 2020?");
Level of knowledge graph search.
</ParamField>

<ParamField path="kg_search_generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
<ParamField path="generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
Configuration for knowledge graph search generation.
</ParamField>

Expand Down Expand Up @@ -620,7 +620,7 @@ Note that any of the customization seen in AI powered search and RAG documentati
Whether to use knowledge graph search.
</ParamField>

<ParamField path="kg_search_generation_config" type="object">
<ParamField path="generation_config" type="object">
Optional configuration for knowledge graph search generation.
</ParamField>

Expand Down
8 changes: 4 additions & 4 deletions docs/documentation/python-sdk/retrieval.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ search_response = client.search("What was Uber's profit in 2020?")
Level of knowledge graph search.
</ParamField>

<ParamField path="kg_search_generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
<ParamField path="generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
Configuration for knowledge graph search generation.
</ParamField>

Expand Down Expand Up @@ -206,7 +206,7 @@ kg_search_response = client.search(
"use_kg_search": True,
"kg_search_type": "local",
"kg_search_level": "0",
"kg_search_generation_config": {
"generation_config": {
"model": "gpt-4o-mini",
"temperature": 0.7,
},
Expand Down Expand Up @@ -393,7 +393,7 @@ rag_response = client.rag("What was Uber's profit in 2020?")
Level of knowledge graph search.
</ParamField>

<ParamField path="kg_search_generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
<ParamField path="generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
Configuration for knowledge graph search generation.
</ParamField>

Expand Down Expand Up @@ -703,7 +703,7 @@ Note that any of the customization seen in AI powered search and RAG documentati
Level of knowledge graph search.
</ParamField>

<ParamField path="kg_search_generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
<ParamField path="generation_config" type="Optional[GenerationConfig]" default="GenerationConfig()">
Configuration for knowledge graph search generation.
</ParamField>

Expand Down
4 changes: 2 additions & 2 deletions js/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "r2r-js",
"version": "0.3.2",
"version": "0.3.3",
"description": "",
"main": "dist/index.js",
"browser": "dist/index.browser.js",
Expand Down
3 changes: 2 additions & 1 deletion js/sdk/src/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface VectorSearchSettings {
use_hybrid_search?: boolean;
filters?: Record<string, any>;
search_limit?: number;
offset?: number;
selected_collection_ids?: string[];
index_measure: IndexMeasure;
include_values?: boolean;
Expand All @@ -54,7 +55,7 @@ export interface KGSearchSettings {
use_kg_search?: boolean;
kg_search_type?: "global" | "local";
kg_search_level?: number | null;
kg_search_generation_config?: GenerationConfig;
generation_config?: GenerationConfig;
entity_types?: any[];
relationships?: any[];
max_community_description_length?: number;
Expand Down
Loading
Loading