-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore/56 option to include large unused dependencies (#60)
* chore: Add new `e5` and `e5-cpu` extras * feat: Make OpenAIEmbedder the default, over E5Embedder * chore: Change torch version to +cpu * chore: Pin torch-cpu version * chore: Remove +cpu * feat: Add `is_installed` and `raise_if_not_installed` convenience functions * chore: Remove all extras * docs: Remove extras from readme * feat: Add `RagSystem.from_config` class method * feat: More extras * feat: Add Demo.from_config * style: Rename script commands * feat: Add CLI module * style: Type hints * feat: Allow JSON config * feat: Loading of config * fix: Rename Openai to OpenAI, load from config correctly * fix: `from_config` takes in a file name * docs: Update changelog * docs: Update changelog * chore: Add cpu extra to CI * fix: Deal with torch CI bug * chore: Do not install vllm if 'cpu' extra is enabled * chore: Remove vllm during CI * chore: Update torch in CI * chore: Update deps for CI * chore: CI * chore: Torch CI * fix: psycopg2 vs psycopg2-binary * tests: Skip tests if generator can't be initialised * chore: Add ExtraMissing * style: MissingExtra and MissingPackage messages * tests: Skip on MissingExtra * fix: Change psycopg2-binary to psycopg2 * fix: Psycopg2
- Loading branch information
1 parent
33d3413
commit cdbaf0e
Showing
18 changed files
with
1,196 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,26 +26,19 @@ Developer(s): | |
Installation with `pip`: | ||
|
||
```bash | ||
pip install ragger[all]@git+ssh://[email protected]/alexandrainst/ragger.git | ||
pip install ragger[default]@git+ssh://[email protected]/alexandrainst/ragger.git | ||
``` | ||
|
||
Installation with `poetry`: | ||
|
||
```bash | ||
poetry add git+ssh://[email protected]/alexandrainst/ragger.git --extras all | ||
poetry add git+ssh://[email protected]/alexandrainst/ragger.git --extras default | ||
``` | ||
|
||
You can replace the `all` extra with any combination of the following, to install only | ||
the components you need: | ||
|
||
- `postgres` | ||
- `vllm` | ||
- `openai` | ||
- `demo` | ||
|
||
For `pip`, this is done by comma-separating the extras (e.g., `ragger[vllm,demo]`), | ||
while for `poetry`, you add multiple `--extras` flags (e.g., `--extras vllm --extras | ||
demo`). | ||
The `default` extra will make sure that you have all the necessary dependencies for | ||
the default components (see below). If you want to use other components, you usually | ||
need to install additional dependencies - these will be listed to you when you try to | ||
use these components. | ||
|
||
|
||
## Quick Start | ||
|
@@ -99,8 +92,8 @@ imported from `ragger.document_store`. | |
|
||
Embedders are used to embed documents. These can all be imported from `ragger.embedder`. | ||
|
||
- `E5Embedder`: An embedder that uses an E5 model. (default) | ||
- `OpenAIEmbedder`: An embedder that uses the OpenAI Embeddings API. | ||
- `OpenAIEmbedder`: An embedder that uses the OpenAI Embeddings API. (default) | ||
- `E5Embedder`: An embedder that uses an E5 model. | ||
|
||
|
||
### Embedding Stores | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Command-line interface for the `ragger` package.""" | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
import click | ||
|
||
from .demo import Demo | ||
from .rag_system import RagSystem | ||
|
||
logger = logging.getLogger(__package__) | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--config_file", | ||
"-c", | ||
default=None, | ||
type=click.Path(exists=True, dir_okay=False), | ||
help="Path to the configuration file, which should be a JSON or YAML file.", | ||
) | ||
def run_demo(config_file: Path | None) -> None: | ||
"""Run a RAG demo. | ||
Args: | ||
config_file: | ||
Path to the configuration file. | ||
""" | ||
rag_system = RagSystem.from_config(config_file=config_file) | ||
demo = Demo.from_config(rag_system=rag_system, config_file=config_file) | ||
demo.launch() | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"--config_file", | ||
"-c", | ||
default=None, | ||
type=click.Path(exists=True, dir_okay=False), | ||
help="Path to the configuration file, which should be a JSON or YAML file.", | ||
) | ||
def compile(config_file: Path) -> None: | ||
"""Compile a RAG system. | ||
Args: | ||
config_file: | ||
Path to the configuration file. | ||
""" | ||
RagSystem.from_config(config_file=config_file) | ||
logger.info("RAG system compiled successfully.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
"""Store and fetch documents from a database.""" | ||
|
||
import importlib.util | ||
import json | ||
import sqlite3 | ||
import typing | ||
from contextlib import contextmanager | ||
from pathlib import Path | ||
|
||
from .data_models import Document, DocumentStore, Index | ||
from .utils import is_installed, raise_if_not_installed | ||
|
||
if importlib.util.find_spec("psycopg2") is not None: | ||
if is_installed(package_name="psycopg2"): | ||
import psycopg2 | ||
|
||
if typing.TYPE_CHECKING: | ||
|
@@ -300,13 +300,11 @@ def __init__( | |
The name of the column in the table that stores the document text. | ||
Defaults to "text". | ||
""" | ||
psycopg2_not_installed = importlib.util.find_spec("psycopg2") is None | ||
if psycopg2_not_installed: | ||
raise ImportError( | ||
"The `postgres` extra is required to use the `PostgresDocumentStore`. " | ||
"Please install it by running `pip install ragger[postgres]@" | ||
"git+ssh://[email protected]/alexandrainst/ragger.git` and try again." | ||
) | ||
raise_if_not_installed( | ||
package_names=["psycopg2"], | ||
extras_mapping=dict(psycopg2="postgres"), | ||
installation_alias_mapping=dict(psycopg2="psycopg2-binary"), | ||
) | ||
|
||
self.host = host | ||
self.port = port | ||
|
@@ -333,7 +331,9 @@ def __init__( | |
) | ||
|
||
@contextmanager | ||
def _connect(self) -> typing.Generator[psycopg2.extensions.connection, None, None]: | ||
def _connect( | ||
self, | ||
) -> "typing.Generator[psycopg2.extensions.connection, None, None]": | ||
"""Connect to the PostgreSQL database. | ||
Yields: | ||
|
Oops, something went wrong.