Skip to content

Commit

Permalink
add examples docs
Browse files Browse the repository at this point in the history
  • Loading branch information
micpst committed Nov 6, 2024
1 parent d36ec1f commit c609e6c
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
- [X] **[Core](packages/ragbits-core)** - Fundamental tools for working with prompts and LLMs.
- [X] **[Document Search](packages/ragbits-document-search)** - Handles vector search to retrieve relevant documents.
- [X] **[CLI](packages/ragbits-cli)** - The `ragbits` shell command, enabling tools such as GUI prompt management.
- [x] **[Guardrails](packages/ragbits-guardrails)** - Ensures response safety and relevance.
- [x] **[Evaluation](packages/ragbits-evaluate)** - Unified evaluation framework for Ragbits components.
- [ ] **Flow Controls** - Manages multi-stage chat flows for performing advanced actions *(coming soon)*.
- [ ] **Structured Querying** - Queries structured data sources in a predictable manner *(coming soon)*.
- [ ] **Caching** - Adds a caching layer to reduce costs and response times *(coming soon)*.
- [ ] **Observability & Audit** - Tracks user queries and events for easier troubleshooting *(coming soon)*.
- [ ] **Guardrails** - Ensures response safety and relevance *(coming soon)*.

## Installation

Expand Down
25 changes: 25 additions & 0 deletions examples/document-search/basic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
"""
Ragbits Document Search Example: Basic
This example demonstrates how to use the `DocumentSearch` class to search for documents with a minimal setup.
We will use the `LiteLLMEmbeddings` class to embed the documents and the query and the `InMemoryVectorStore` class
to store the embeddings.
The script performs the following steps:
1. Create a list of documents.
2. Initialize the `LiteLLMEmbeddings` class with the OpenAI `text-embedding-3-small` embedding model.
3. Initialize the `InMemoryVectorStore` class.
4. Initialize the `DocumentSearch` class with the embedder and the vector store.
5. Ingest the documents into the `DocumentSearch` instance.
6. Search for documents using a query.
7. Print the search results.
To run the script, execute the following command:
```bash
uv run examples/document-search/basic.py
```
"""

# /// script
# requires-python = ">=3.10"
# dependencies = [
# "ragbits-document-search",
# "ragbits-core[litellm]",
# ]
# ///

import asyncio

from ragbits.core.embeddings.litellm import LiteLLMEmbeddings
Expand Down
26 changes: 26 additions & 0 deletions examples/document-search/chroma.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
"""
Ragbits Document Search Example: Chroma
This example demonstrates how to use the `DocumentSearch` class to search for documents with a more advanced setup.
We will use the `LiteLLMEmbeddings` class to embed the documents and the query, the `ChromaVectorStore` class to store
the embeddings.
The script performs the following steps:
1. Create a list of documents.
2. Initialize the `LiteLLMEmbeddings` class with the OpenAI `text-embedding-3-small` embedding model.
3. Initialize the `ChromaVectorStore` class with a `PersistentClient` instance and an index name.
4. Initialize the `DocumentSearch` class with the embedder and the vector store.
5. Ingest the documents into the `DocumentSearch` instance.
6. List all documents in the vector store.
7. Search for documents using a query.
8. Print the list of all documents and the search results.
To run the script, execute the following command:
```bash
uv run examples/document-search/chroma.py
```
"""

# /// script
# requires-python = ">=3.10"
# dependencies = [
# "ragbits-document-search",
# "ragbits-core[chroma,litellm]",
# ]
# ///

import asyncio

from chromadb import PersistentClient
Expand Down
44 changes: 44 additions & 0 deletions examples/document-search/chroma_otel.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
"""
Ragbits Document Search Example: Chroma x OpenTelemetry
This example demonstrates how to use the `DocumentSearch` class to search for documents with a more advanced setup.
We will use the `LiteLLMEmbeddings` class to embed the documents and the query, the `ChromaVectorStore` class to store
the embeddings, and the OpenTelemetry SDK to trace the operations.
The script performs the following steps:
1. Create a list of documents.
2. Initialize the `LiteLLMEmbeddings` class with the OpenAI `text-embedding-3-small` embedding model.
3. Initialize the `ChromaVectorStore` class with a `PersistentClient` instance and an index name.
4. Initialize the `DocumentSearch` class with the embedder and the vector store.
5. Ingest the documents into the `DocumentSearch` instance.
6. List all documents in the vector store.
7. Search for documents using a query.
8. Print the list of all documents and the search results.
To run the script, execute the following command:
```bash
uv run examples/document-search/chroma_otel.py
```
The script exports traces to the local OTLP collector running on `http://localhost:4317`. To visualize the traces,
you can use Jeager. The recommended way to run it is using the official Docker image:
1. Run Jaeger Docker container:
```bash
docker run -d --rm --name jaeger \
-p 16686:16686 \
-p 4317:4317 \
jaegertracing/all-in-one:1.62.0
```
2. Open the Jaeger UI in your browser:
```
http://localhost:16686
```
"""

# /// script
# requires-python = ">=3.10"
# dependencies = [
# "ragbits-document-search",
# "ragbits-core[chroma,litellm,otel]",
# ]
# ///

import asyncio

from chromadb import PersistentClient
Expand Down
23 changes: 23 additions & 0 deletions examples/document-search/from_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
"""
Ragbits Document Search Example: DocumentSearch from Config
This example demonstrates how to use the `DocumentSearch` class to search for documents with a more advanced setup.
We will use the `LiteLLMEmbeddings` class to embed the documents and the query, the `ChromaVectorStore` class to store
the embeddings, and the `LiteLLMReranker` class to rerank the search results. We will also use the `LLMQueryRephraser`
class to rephrase the query.
The script performs the following steps:
1. Create a list of documents.
2. Initialize the `DocumentSearch` class with the predefined configuration.
3. Ingest the documents into the `DocumentSearch` instance.
4. Search for documents using a query.
5. Print the search results.
To run the script, execute the following command:
```bash
uv run examples/document-search/from_config.py
```
"""
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "ragbits-document-search",
# "ragbits-core[chroma,litellm]",
# ]
# ///

import asyncio

from ragbits.document_search import DocumentSearch
Expand Down

0 comments on commit c609e6c

Please sign in to comment.