-
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.
- Loading branch information
Showing
28 changed files
with
437 additions
and
90 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
41 changes: 41 additions & 0 deletions
41
src/content/docs/getting-started/architecture-and-design.mdx
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,41 @@ | ||
--- | ||
title: Architecture and Design | ||
description: The architecture and design principles of the Swiftide project. | ||
--- | ||
|
||
## Design principles | ||
|
||
- **Modular**: The pipeline is built from small, composable parts. | ||
- **Extensible**: It is easy to add new parts to the pipeline by extending straightforward traits. | ||
- **Performance**: Performance and ease-of-use are the main goals of the library. Performance always has priority. | ||
- **Tracable**: `tracing` is used throughout the pipeline. | ||
|
||
### When designing integrations, transformers, chunkers | ||
|
||
- **Simple**: The API should be simple and easy to use. | ||
- **Sane defaults, fully configurable**: The library should have sane defaults that are easy to override. | ||
- **Builder pattern**: The builder pattern is used to create new instances of the pipeline. | ||
|
||
## The-things-we-talk-about | ||
|
||
- **IngestionPipeline**: The main struct that holds the pipeline. It is a stream of IngestionNodes. | ||
- **IngestionNode**: The main struct that holds the data. It has a path, chunk and metadata. | ||
- **IngestionStream**: The internal stream of IngestionNodes in the pipeline. | ||
- **Loader**: The starting point of the stream, creates and emits IngestionNodes. | ||
- **Transformers**: Some behaviour that modifies the IngestionNodes. | ||
- **BatchTransformers**: Transformers that transform multiple nodes. | ||
- **Chunkers**: Transformers that split a node into multiple nodes. | ||
- **Storages**: Persist the IngestionNodes. | ||
- **NodeCache**: Filters cached nodes. | ||
- **Integrations**: External libraries that can be used with the pipeline. | ||
|
||
### Pipeline structure and traits | ||
|
||
- from_loader (impl Loader) starting point of the stream, creates and emits IngestionNodes | ||
- filter_cached (impl NodeCache) filters cached nodes | ||
- then (impl Transformer) transforms the node and puts it on the stream | ||
- then_in_batch (impl BatchTransformer) transforms multiple nodes and puts them on the stream | ||
- then_chunk (impl ChunkerTransformer) transforms a single node and emits multiple nodes | ||
- then_store_with (impl Storage) stores the nodes in a storage backend, this can be chained | ||
|
||
Additionally, several generic transformers are implemented. They take implementers of `SimplePrompt` and `EmbeddingModel` to do their things. |
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,5 +1,6 @@ | ||
--- | ||
title: Feature Flags | ||
description: Available features and integrations in Swiftide. | ||
sidebar: | ||
order: 1 | ||
--- | ||
|
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,5 +1,6 @@ | ||
--- | ||
title: Installation | ||
description: Installation instructions for Swiftide. | ||
sidebar: | ||
order: 0 | ||
--- | ||
|
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,31 @@ | ||
--- | ||
title: Caching and filtering nodes | ||
description: How to cache and filter nodes in the pipeline. | ||
sidebar: | ||
order: 3 | ||
--- | ||
|
||
When nodes have already been processed by the pipeline, they can often be skipped, speeding up the pipeline and saving costs. A node cache implements the `NodeCache` trait. | ||
|
||
## The `NodeCache` trait | ||
|
||
Which is defined as follows: | ||
|
||
```rust | ||
pub trait NodeCache: Send + Sync + Debug { | ||
async fn get(&self, node: &IngestionNode) -> bool; | ||
async fn set(&self, node: &IngestionNode); | ||
} | ||
``` | ||
|
||
Or in human language: "Given a Node, provide methods to set and get from the cache". | ||
|
||
## Built in chunkers | ||
|
||
<small> | ||
|
||
| Name | Description | Feature Flag | | ||
| ----- | --------------------------------------------------- | ------------ | | ||
| Redis | Can get and set nodes using multiplexed connections | redis | | ||
|
||
</small> |
3 changes: 3 additions & 0 deletions
3
src/content/docs/concepts/chunking.md → src/content/docs/in-depth/chunking.md
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,31 @@ | ||
--- | ||
title: Loading Data | ||
description: How to load data into the pipeline. | ||
sidebar: | ||
order: 1 | ||
--- | ||
|
||
A pipeline starts with data and is only as good as the data it ingests. A loader implements the `Loader` trait. | ||
|
||
## The `Loader` trait | ||
|
||
Which is defined as follows: | ||
|
||
```rust | ||
pub trait Loader { | ||
fn into_stream(self) -> IngestionStream; | ||
} | ||
``` | ||
|
||
Or in human language: "I can be turned into a stream". The assumption under the hood is that Loaders will yield the data they load as a stream of `IngestionNodes`. These can be files, messages, webpages and so on. | ||
|
||
## Built in loaders | ||
|
||
<small> | ||
|
||
| Name | Description | Feature Flag | | ||
| -------------- | ------------------------------------------------------------------- | ------------ | | ||
| FileLoader | Loads files with an optional extension filter, respecting gitignore | | | ||
| ScrapingLoader | Scrapes a website using the `spider` crate | scraping | | ||
|
||
</small> |
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,43 @@ | ||
--- | ||
title: Prompting and Embedding | ||
description: How to prompt and embed data in the pipeline. | ||
sidebar: | ||
order: 2 | ||
--- | ||
|
||
Our metadata transformers are generic over the `SimplePrompt` trait. This enables different models to be used for different usecases. Similarly, the embedding transformer is generic over the `EmbeddingModel` trait. | ||
|
||
## The `SimplePrompt` trait | ||
|
||
Which is defined as follows: | ||
|
||
```rust | ||
pub trait SimplePrompt: Debug + Send + Sync { | ||
async fn prompt(&self, prompt: &str) -> Result<String>; | ||
} | ||
``` | ||
|
||
Or in human language: "Given a Prompt, give me a response". | ||
|
||
## The `EmbeddingModel` trait | ||
|
||
Which is defined as follows: | ||
|
||
```rust | ||
pub trait EmbeddingModel: Send + Sync { | ||
async fn embed(&self, input: Vec<String>) -> Result<Embeddings>; | ||
} | ||
``` | ||
|
||
Or in human language: "Given a list of things to Embed, give me embeddings". The embedding transformer will link back the embeddings to the original nodes by _order_. | ||
|
||
## Built in inference and embedding models | ||
|
||
<small> | ||
|
||
| Name | Description | Feature Flag | | ||
| --------- | --------------------------------------------------------- | ------------ | | ||
| OpenAI | Implements both SimplePrompt and Embed via `async_openai` | openai | | ||
| FastEmbed | Implements Embed via `fastembed-rs` | fastembed | | ||
|
||
</small> |
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,39 @@ | ||
--- | ||
title: Storing the results | ||
description: How to store the results of the pipeline. | ||
sidebar: | ||
order: 5 | ||
--- | ||
|
||
After processing nodes in the pipeline you probably want to store the results. Pipelines support multiple storage steps, but need at least one. A storage implements the `Persist` trait. | ||
|
||
## The `Persist` trait | ||
|
||
Which is defined as follows: | ||
|
||
```rust | ||
pub trait Persist: Debug + Send + Sync { | ||
async fn setup(&self) -> Result<()>; | ||
async fn store(&self, node: IngestionNode) -> Result<IngestionNode>; | ||
async fn batch_store(&self, nodes: Vec<IngestionNode>) -> IngestionStream; | ||
fn batch_size(&self) -> Option<usize> { | ||
None | ||
} | ||
} | ||
``` | ||
|
||
Setup functions are run right away, asynchronously when the pipeline starts. This could include setting up collections, tables, connections etcetera. Because more might happen after storing, both `store` and `batch_store` are expected to return the nodes they processed. | ||
|
||
If `batch_size` is implemented for the storage, the stream will always prefer `batch_store`. | ||
|
||
## Built in storage | ||
|
||
<small> | ||
|
||
| Name | Description | Feature Flag | | ||
| ------------- | ---------------------------------------------------- | ------------ | | ||
| Redis | Persists nodes by default as json | redis | | ||
| Qdrant | Persists nodes in qdrant; expects a vector to be set | qdrant | | ||
| MemoryStorage | Persists nodes in memory; great for debugging | | | ||
|
||
</small> |
Oops, something went wrong.