Skip to content

Commit

Permalink
Dev rebased (#332)
Browse files Browse the repository at this point in the history
* update the default embd. (#310)

* Feature/add jina reranker rebased (#312)

* Add jina reranker

* fix oai

* Revampt client & server approach. (#316)

* Revampt client & server approach.

* cleanups

* tweak hyde prompt

* Feature/add agent provider (#317)

* update pipeline (#315)

* Update CONTRIBUTING.md

* Delete CONTRIBUTOR.md

* Adding agent provider

* Feature/add agent provider rebased v2 (#319)

* modify prompt provider workflow, add agent

* fix run qna client

* add provider abstraction

* tweaks and cleans

* move text splitter config locale

* Feature/modify get all uniq values (#325)

* refine

* update

* format

* fix

* Feature/dev merge rebased (#329)

* Update local_rag.mdx

* Update llms.mdx (#322)

* update the default embd. (#310)

* Feature/add agent provider (#317)

* update pipeline (#315)

* Update CONTRIBUTING.md

* Delete CONTRIBUTOR.md

* Adding agent provider

* Feature/modify get all uniq values (#325)

* refine

* update

* format

* fix

* dev merge

* Feature/fix dev merge mistakes rebased (#330)

* Feature/add agent provider (#317)

* update pipeline (#315)

* Update CONTRIBUTING.md

* Delete CONTRIBUTOR.md

* Adding agent provider

* Feature/modify get all uniq values (#325)

* refine

* update

* format

* fix

* dev merge

* cleanup

* Feature/dev cleanup (#331)

* final pub

* final pub

* json clean

* fix sentence transformer issue

* include rerank

* fix llama cpp

* rebase

* fix rerank

* small tweaks

* rollbk config

* cleanup
  • Loading branch information
emrgnt-cmplxty committed Apr 24, 2024
1 parent 511367e commit 510224f
Show file tree
Hide file tree
Showing 74 changed files with 2,692 additions and 1,772 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ env/
node_modules


**/*.sqlite
**/*.sqlite3
**/*.sqlite*
**/*.sqlite3*

qdrant_storage/
qdrant_storage/
r2r/examples/data/*
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ R2R was conceived to bridge the gap between local LLM experimentation and scalab
- **⚖️ Autoscale**: Scale your pipeline effortlessly in the cloud using [SciPhi](https://sciphi.ai/).
- **🤖 OSS**: Benefit from a framework developed by the open-source community, designed to simplify RAG deployment.

# Table of Contents
1. [Demo(s)](#demos)
2. [Links](#links)
3. [Quick Install](#quick-install)
4. [Docker](#docker)
5. [Q&A Example](#q&a-example)
6. [HyDE Example](#hyde-example)
7. [Running Local RAG](#running-local-rag)
8. [Core Abstractions](#core-abstractions)


## Demo(s)

Using the cloud application to deploy the pre-built basic pipeline:
Expand Down Expand Up @@ -73,13 +84,13 @@ docker pull emrgntcmplxty/r2r:latest
docker run -d --name r2r_container -p 8000:8000 -e CONFIG_OPTION=local_ollama emrgntcmplxty/r2r:latest
```

## Basic Example
## Q&A Example

[`Configurable Pipeline`](r2r/examples/servers/config_pipeline.py): Execute this script to select and serve a **Q&A RAG**, **Web RAG**, or **Agent RAG** pipeline. This starter pipeline supports ingestion, embedding, and question and the specified RAG, all accessible via a REST API.
```bash
# launch the server
# For ex., do `export CONFIG_OPTION=local_ollama` or ``--config=local_ollama` to run fully locally
# For ex., do `export PIPELINE_OPTION=web` or ``--pipeline=web` to run WebRAG pipeline
# For ex., do `export CONFIG_OPTION=local_ollama` or `--config=local_ollama` to run fully locally
# For ex., do `export PIPELINE_OPTION=web` or `--pipeline=web` to run WebRAG pipeline
python -m r2r.examples.servers.config_pipeline --config=default --pipeline=qna
```

Expand Down Expand Up @@ -113,39 +124,34 @@ docker run -d --name r2r_container -p 8000:8000 -e CONFIG_OPTION=local_ollama e
python -m r2r.examples.clients.run_qna_client rag_completion_streaming --query="What was lyfts profit in 2020?"

# <search>[{"id": "a0f6b427-9083-5ef2-aaa1-024b6cebbaee", "score": 0.6862949051074227, "metadata": {"user_id": "df7021ed-6e66-5581-bd69-d4e9ac1e5ada", "pipeline_run_id": "0c2c9a81-0720-4e34-8736-b66189956013", "text": "Title: Lyft 10k 2021\nNet loss was $ ... </search>

#
# <context> Title: Lyft 10k 2021 ... </context>

#
# <completion>Lyft's net loss in 2020 was $1.8 billion.</completion>
```
### Running Local RAG

[Refer here](https://r2r-docs.sciphi.ai/tutorials/local_rag) for a tutorial on how to modify the commands above to use local providers.

## Synthetic Queries Example
## HyDE Example

[`Synthetic Query Pipeline`](r2r/examples/servers/synthetic_query_pipeline.py): Execute this script to start a backend server equipped with more advanced synthetic query pipeline. This pipeline is designed to create synthetic queries, enhancing the RAG system's learning and performance.
[`HyDE Pipeline`](r2r/examples/servers/hyde_pipeline.py): Execute this script to start a backend server equipped with more advanced synthetic query pipeline. This pipeline is designed to create synthetic queries, enhancing the RAG system's learning and performance.

```bash
# launch the server
python -m r2r.examples.servers.synthetic_query_pipeline
python -m r2r.examples.servers.config_pipeline --config=default --pipeline=hyde
```

[`Synthetic Query Client`](r2r/examples/clients/run_synthetic_query_client.py): Use this client script after the synthetic query pipeline is running. It's tailored for use with the synthetic query pipeline, demonstrating the improved features of the RAG system.

```bash
# ingests Lyft 10K, Uber 10K, and others
python -m r2r.examples.clients.run_qna_client ingest --document_filter=all

# run the client
python -m r2r.examples.clients.run_synthetic_query_client
```
python -m r2r.examples.clients.run_qna_client search --query="What was lyft and ubers profit in 2020?"

## Extra Examples
# {... 'message': {'content': 'In 2020, Lyft reported a net loss of $1.7529 billion [8]. Uber also reported a significant loss for the year 2020, with its net loss improving by $1.8 billion from 2020, indicating a substantial loss for the year as well [38]. Neither company achieved a profit in 2020; instead, they both experienced considerable losses.' ...}
```

[`Reducto Pipeline`](r2r/examples/servers/reducto_pipeline.py): Launch this script to activate a backend server that integrates a Reducto adapter for enhanced PDF ingestion.
## Running Local RAG

```bash
# launch the server
python -m r2r.examples.servers.reducto_pipeline
```
[Refer here](https://r2r-docs.sciphi.ai/tutorials/local_rag) for a tutorial on how to modify the commands above to use local providers.

## Core Abstractions

Expand Down
34 changes: 17 additions & 17 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
{
"embedding": {
"provider": "openai",
"model": "text-embedding-3-small",
"dimension": 1536,
"batch_size": 32
},
"evals": {
"provider": "parea",
"frequency": 1.0
},
"language_model": {
"provider": "litellm"
},
"logging_database": {
"vector_database": {
"provider": "local",
"collection_name": "demo_logs",
"level": "INFO"
"collection_name": "demo_vecs"
},
"ingestion":{
"provider": "local",
"provider": "local"
},
"embedding": {
"provider": "openai",
"search_model": "text-embedding-3-small",
"search_dimension": 512,
"batch_size": 32,
"text_splitter": {
"type": "recursive_character",
"chunk_size": 512,
"chunk_overlap": 20
}
},
"vector_database": {
"provider": "local",
"collection_name": "demo_vecs"
"evals": {
"provider": "parea",
"frequency": 0.0
},
"app": {
"max_logs": 100,
"max_file_size_in_mb": 100
},
"logging_database": {
"provider": "local",
"collection_name": "demo_logs",
"level": "INFO"
}
}
12 changes: 6 additions & 6 deletions docs/pages/deep-dive/app.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ The application uses a configuration file (`config.json`) to set various setting
"provider": "openai",
"model": "text-embedding-3-small",
"dimension": 1536,
"batch_size": 32
"batch_size": 32,
"text_splitter": {
"type": "recursive_character",
"chunk_size": 512,
"chunk_overlap": 20
}
},
"evals": {
"provider": "deepeval",
Expand All @@ -99,11 +104,6 @@ The application uses a configuration file (`config.json`) to set various setting
},
"ingestion": {
"provider": "local",
"text_splitter": {
"type": "recursive_character",
"chunk_size": 512,
"chunk_overlap": 20
}
},
"vector_database": {
"provider": "local",
Expand Down
14 changes: 7 additions & 7 deletions docs/pages/deep-dive/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ The default values for the config are shown below:
"provider": "openai",
"model": "text-embedding-ada-002",
"dimension": 1536,
"batch_size": 32
"batch_size": 32,
"text_splitter": {
"type": "recursive_character",
"chunk_size": 512,
"chunk_overlap": 20
}
},
"evals": {
"provider": "deepeval",
Expand All @@ -32,12 +37,7 @@ The default values for the config are shown below:
"level": "INFO"
},
"ingestion": {
"provider": "local",
"text_splitter": {
"type": "recursive_character",
"chunk_size": 512,
"chunk_overlap": 20
}
"provider": "local"
},
"vector_database": {
"provider": "local",
Expand Down
12 changes: 5 additions & 7 deletions docs/pages/deep-dive/embedding.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The `BasicEmbeddingPipeline` is a simple implementation of the `EmbeddingPipelin

### Initialization

The `BasicEmbeddingPipeline` is initialized with the `embedding_model`, `embeddings_provider`, `db`, `text_splitter`, an optional `logging_connection`, `embedding_batch_size`, and `id_prefix`.
The `BasicEmbeddingPipeline` is initialized with an `embedding_provider`, `vector_db_provider`, `text_splitter`, an optional `logging_connection`, `embedding_batch_size`, and `id_prefix`.

### Text Extraction

Expand Down Expand Up @@ -70,18 +70,16 @@ import textstat
class CustomEmbeddingPipeline(BasicEmbeddingPipeline):
def __init__(
self,
embedding_model: str,
embeddings_provider: OpenAIEmbeddingProvider,
db: VectorDBProvider,
embedding_provider: OpenAIEmbeddingProvider,
vector_db_provider: VectorDBProvider,
text_splitter: TextSplitter,
logging_connection: Optional[LoggingDatabaseConnection] = None,
embedding_batch_size: int = 1,
id_prefix: str = "demo",
):
super().__init__(
embedding_model,
embeddings_provider,
db,
embedding_provider,
vector_db_provider,
text_splitter,
logging_connection,
embedding_batch_size,
Expand Down
20 changes: 9 additions & 11 deletions docs/pages/deep-dive/factory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ from r2r.main import E2EPipelineFactory, R2RConfig

app = E2EPipelineFactory.create_pipeline(
config=R2RConfig.load_config(),
db=None,
embeddings_provider=None,
llm=None,
text_splitter=None,
vector_db_provider=None,
embedding_provider=None,
llm_provider=None,
adapters=None,
ingestion_pipeline_impl=BasicIngestionPipeline,
embedding_pipeline_impl=BasicEmbeddingPipeline,
Expand All @@ -37,7 +36,7 @@ This method retrieves the appropriate vector database based on the `database_con
- `pgvector`: Returns an instance of `PGVectorDB`.
- `local`: Returns an instance of `LocalVectorDB`.

### `get_embeddings_provider(embedding_config: dict[str, Any])`
### `get_embedding_provider(embedding_config: dict[str, Any])`

This method retrieves the appropriate embeddings provider based on the `embedding_config`. It supports the following embeddings providers:
- `openai`: Returns an instance of `OpenAIEmbeddingProvider`.
Expand All @@ -46,8 +45,8 @@ This method retrieves the appropriate embeddings provider based on the `embeddin
### `get_llm(llm_config: dict[str, Any])`

This method retrieves the appropriate language model based on the `llm_config`. It supports the following language models:
- `openai`: Returns an instance of `OpenAILLM` with the `OpenAIConfig`.
- `litellm`: Returns an instance of `LiteLLM` with the `LiteLLMConfig`.
- `openai`: Returns an instance of `OpenAILLM`.
- `litellm`: Returns an instance of `LiteLLM`.

### `get_text_splitter(text_splitter_config: dict[str, Any])`

Expand All @@ -58,13 +57,12 @@ This method retrieves the appropriate text splitter based on the `text_splitter_
This method creates the end-to-end pipeline by assembling various components based on the provided `config` and optional parameters. It performs the following steps:

1. Sets up logging based on the `logging_database` configuration.
2. Retrieves the embeddings provider using `get_embeddings_provider` or uses the provided `embeddings_provider`.
3. Retrieves the vector database using `get_vector_db` or uses the provided `db`.
2. Retrieves the embeddings provider using `get_embedding_provider` or uses the provided `embedding_provider`.
3. Retrieves the vector database using `get_vector_db_provider` or uses the provided `vector_db_provider`.
4. Initializes the vector database collection with the specified `collection_name` and `embedding_dimension`.
5. Retrieves the language model using `get_llm` or uses the provided `llm`.
5. Retrieves the language model using `get_llm_provider` or uses the provided `llm`.
6. Creates a `LoggingDatabaseConnection` instance for logging purposes.
7. Creates an instance of the `rag_pipeline_impl` (default: `QnARAGPipeline`) with the language model, vector database, embedding model, embeddings provider, and logging connection.
8. Retrieves the text splitter using `get_text_splitter` or uses the provided `text_splitter`.
9. Creates an instance of the `embedding_pipeline_impl` (default: `BasicEmbeddingPipeline`) with the embedding model, embeddings provider, vector database, logging connection, text splitter, and embedding batch size.
10. Creates an instance of the `eval_pipeline_impl` (default: `BasicEvalPipeline`) with the evaluation configuration and logging connection.
11. Creates an instance of the `ingestion_pipeline_impl` (default: `BasicIngestionPipeline`) with the specified adapters.
Expand Down
30 changes: 13 additions & 17 deletions docs/pages/deep-dive/rag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ The `QnARAGPipeline` is a simple implementation of the `RAGPipeline` abstract ba
### Initialization

The `QnARAGPipeline` is initialized with the following parameters:
- `llm`: An instance of `LLMProvider` for generating completions.
- `db`: An instance of `VectorDBProvider` for searching and retrieving documents.
- `embedding_model`: The name of the embedding model to use.
- `embeddings_provider`: An instance of `OpenAIEmbeddingProvider` for generating embeddings.
- `llm_provider`: An instance of `LLMProvider` for generating completions.
- `vector_db_provider`: An instance of `VectorDBProvider` for searching and retrieving documents.
- `embedding_provider`: An instance of `OpenAIEmbeddingProvider` for generating embeddings.
- `prompt_provider` (optional): An instance of `PromptProvider` for providing prompts (default is `BasicPromptProvider`).
- `logging_connection` (optional): An instance of `LoggingDatabaseConnection` for logging.

Expand Down Expand Up @@ -40,10 +39,9 @@ To create a custom RAG pipeline, you can subclass the `RAGPipeline` abstract bas
class CustomRAGPipeline(RAGPipeline):
def __init__(
self,
llm: LLMProvider,
db: VectorDBProvider,
embedding_model: str,
embeddings_provider: OpenAIEmbeddingProvider,
llm_provider: LLMProvider,
vector_db_provider: VectorDBProvider,
embedding_provider: OpenAIEmbeddingProvider,
prompt_provider: Optional[PromptProvider] = None,
logging_connection: Optional[LoggingDatabaseConnection] = None,
) -> None:
Expand All @@ -52,13 +50,12 @@ class CustomRAGPipeline(RAGPipeline):
self.prompt_provider = prompt_provider

super().__init__(
llm,
llm_provider=llm_provider,
prompt_provider=prompt_provider,
embedding_provider=embedding_provider,
vector_db_provider=vector_db_provider,
logging_connection=logging_connection,
)
self.embedding_model = embedding_model
self.embeddings_provider = embeddings_provider
self.db = db
self.pipeline_run_info = None

def transform_query(self, query: str) -> str:
Expand All @@ -75,21 +72,20 @@ class CustomRAGPipeline(RAGPipeline):
**kwargs,
) -> list[VectorSearchResult]:
# Custom document retrieval logic
results = self.db.search(
query_vector=self.embeddings_provider.get_embedding(
results = self.vector_db_provider.search(
query_vector=self.embedding_provider.get_embedding(
transformed_query,
self.embedding_model,
),
filters=filters,
limit=limit,
)
return results

def rerank_results(
self, results: list[VectorSearchResult]
self, transformed_query: str, results: list[VectorSearchResult], limit
) -> list[VectorSearchResult]:
# Custom result reranking logic
return list(reversed(results))
return list(reversed(results))[0:limit]

def _format_results(self, results: list[VectorSearchResult]) -> str:
# Custom result formatting logic
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/providers/embeddings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Anything supported by OpenAI, such as:
- **Pricing**: Approximately 12,500 pages per dollar. Balances cost and performance effectively.
- **More**: [Embeddings Guide](https://platform.openai.com/docs/guides/embeddings)

Lastly, the `sentence_transformer` package from HuggingFace is also supported as a provider. For example, one such popular model is [`all-MiniLM-L6-v2`](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2).
Lastly, the `sentence_transformer` package from HuggingFace is also supported as a provider. For example, one such popular model is [`mixedbread-ai/mxbai-embed-large-v1`](https://huggingface.co/sentence-transformers/mixedbread-ai/mxbai-embed-large-v1).
2 changes: 1 addition & 1 deletion docs/pages/providers/llms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pip install llama-cpp-python # or poetry install ... -E local-llm

To configure the LlamaCpp provider, you need to set the following options in the `language_model` section of the configuration file (`config.json`):

- `provider_name`: Set it to `"llama-cpp"` to use the LlamaCpp provider.
- `provider`: Set it to `"llama-cpp"` to use the LlamaCpp provider.
- `model_path`: Specify the path where the LlamaCpp models are located. If not provided, it defaults to `~/.cache/models`.
- `model_name`: Specify the name of the LlamaCpp model to use. If not provided, it defaults to `"tinyllama-1.1b-chat-v1.0.Q2_K.gguf"`.

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/tutorials/configuring_your_rag_pipeline.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Set the `provider` field under `vector_database` in `config.json` to specify you
#### Embedding Provider
R2R supports OpenAI and local inference embedding providers:
- `openai`: OpenAI models like `text-embedding-3-small`
- `sentence-transformers`: HuggingFace models like `all-MiniLM-L6-v2`
- `sentence-transformers`: HuggingFace models like `mixedbread-ai/mxbai-embed-large-v1`
Configure the `embedding` section to set your desired embedding model, dimension, and batch size.
Expand Down

0 comments on commit 510224f

Please sign in to comment.