Skip to content

Commit

Permalink
docs: Update ObjectBox docs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Jun 1, 2024
1 parent 22c3d3f commit 694ca64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions docs/modules/retrieval/vector_stores/integrations/objectbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ObjectBox features:
- Low memory footprint: ObjectBox itself just takes a few MB of memory. The entire binary is only about 3 MB (compressed around 1 MB)
- Scales with hardware: efficient resource usage is also an advantage when running on more capable devices like the latest phones, desktops and servers

Official ObjectBox resources:
- [ObjectBox Vector Search docs](https://docs.objectbox.io/ann-vector-search)
- [The first On-Device Vector Database: ObjectBox 4.0](https://objectbox.io/the-first-on-device-vector-database-objectbox-4-0)
- [On-device Vector Database for Dart/Flutter](https://objectbox.io/on-device-vector-database-for-dart-flutter)
Expand Down Expand Up @@ -42,21 +43,21 @@ dependencies:
### 3. Instantiate the ObjectBox vector store
```dart
final embeddings = OllamaEmbeddings(model: 'mxbai-embed-large:335m');
final embeddings = OllamaEmbeddings(model: 'jina/jina-embeddings-v2-small-en');
final vectorStore = ObjectBoxVectorStore(
embeddings: embeddings,
dimensions: 1024,
dimensions: 512,
);
```

The dimensions parameter specifies the number of dimensions of the embeddings. It will depend on the embeddings model you are using. In this example, we are using the `mxbai-embed-large:335m` model, which has 1024 dimensions.
The dimensions parameter specifies the number of dimensions of the embeddings. It will depend on the embeddings model you are using. In this example, we are using the [jina/jina-embeddings-v2-small-en](https://ollama.com/jina/jina-embeddings-v2-small-en) model, which has 512 dimensions.

The `ObjectBoxVectorStore` constructor allows you to customize the ObjectBox store that is created under the hood. For example, you can change the directory where the database is stored:

```dart
final vectorStore = ObjectBoxVectorStore(
embeddings: embeddings,
dimensions: 1024,
dimensions: 512,
directory: 'path/to/db',
);
```
Expand Down Expand Up @@ -129,15 +130,15 @@ This example demonstrates how to build a fully local RAG (Retrieval-Augmented Ge
Before running the example, make sure you have the following:

- Ollama installed (see the [Ollama documentation](https://ollama.com/) for installation instructions).
- [mxbai-embed-large:335m](https://ollama.com/library/mxbai-embed-large:335m) and [`llama3:8b`](https://ollama.com/library/llama3:8b) models downloaded.
- [jina/jina-embeddings-v2-small-en](https://ollama.com/jina/jina-embeddings-v2-small-en) and [llama3:8b](https://ollama.com/library/llama3:8b) models downloaded.

#### Steps

**Step 1: Retrieving and Storing Documents**

1. Retrieve several posts from the ObjectBox blog using a `WebBaseLoader` document loader.
2. Split the retrieved posts into chunks using a `RecursiveCharacterTextSplitter`.
3. Create embeddings from the document chunks using the `mxbai-embed-large:335m` embeddings model via `OllamaEmbeddings`.
3. Create embeddings from the document chunks using the `jina/jina-embeddings-v2-small-en` embeddings model via `OllamaEmbeddings`.
4. Add the document chunks and their corresponding embeddings to the `ObjectBoxVectorStore`.

> Note: this step only needs to be executed once (unless the documents change). The stored documents can be used for multiple queries.
Expand All @@ -151,8 +152,8 @@ Before running the example, make sure you have the following:
```dart
// 1. Instantiate vector store
final vectorStore = ObjectBoxVectorStore(
embeddings: OllamaEmbeddings(model: 'mxbai-embed-large:335m'),
dimensions: 1024,
embeddings: OllamaEmbeddings(model: 'jina/jina-embeddings-v2-small-en'),
dimensions: 512,
);
// 2. Load documents
Expand Down Expand Up @@ -241,6 +242,10 @@ await stream.forEach(stdout.write);
// [2] https://objectbox.io/on-device-vector-database-for-dart-flutter/
```

## Example: Wikivoyage EU

Check out the [Wikivoyage EU example](https://github.com/davidmigloz/langchain_dart/tree/main/examples/wikivoyage_eu), to see how to build a fully local chatbot that uses RAG to plan vacation plans in Europe.

## Advance

### BaseObjectBoxVectorStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ void main() async {
Future<void> _rag() async {
// 1. Instantiate vector store
final vectorStore = ObjectBoxVectorStore(
embeddings: OllamaEmbeddings(model: 'mxbai-embed-large:335m'),
dimensions: 1024,
embeddings: OllamaEmbeddings(model: 'jina/jina-embeddings-v2-small-en'),
dimensions: 512,
directory: 'bin/modules/retrieval/vector_stores/integrations',
);

Expand Down
2 changes: 1 addition & 1 deletion examples/wikivoyage_eu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Added 160 documents to the vector store.

The chatbot script implements the RAG pipeline. It does the following:
1. Takes a user query as input.
2. Uses the `mxbai-embed-large:335m` model to create an embedding for the query.
2. Uses the `jina/jina-embeddings-v2-small-en` model to create an embedding for the query.
3. Retrieves the 5 most similar documents from the ObjectBox database.
4. Builds a prompt using the retrieved documents and the query.
5. Uses the `llama3:8b` model to generate a response to the prompt.
Expand Down

0 comments on commit 694ca64

Please sign in to comment.