Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,14 @@ content = """
It is known that Maxwell...
"""
documents = [
Document.from_text(content)
Document.from_text(content, author="Einstein", topic="physics", year=1905)
]
insert_documents(documents, config=my_config)
```

> [!TIP]
> 📝 Documents can include metadata by passing keyword arguments to `Document.from_text()` or `Document.from_path()`. This metadata can later be used for filtering during retrieval.

You may also want to expand the document metadata before insertion:

```python
Expand Down Expand Up @@ -226,7 +229,12 @@ my_config = replace(my_config, search_method=vector_search) # Or `hybrid_search

# Retrieve relevant chunk spans with the configured search method
user_prompt = "How is intelligence measured?"
chunk_spans = retrieve_context(query=user_prompt, num_chunks=5, config=my_config)
chunk_spans = retrieve_context(
query=user_prompt,
num_chunks=5,
metadata_filter={"author": "Einstein"}, # Optional: filter by metadata
config=my_config
)

# Append a RAG instruction based on the user prompt and context to the message history
messages = [] # Or start with an existing message history
Expand Down Expand Up @@ -263,7 +271,9 @@ from raglite import hybrid_search, keyword_search, vector_search
user_prompt = "How is intelligence measured?"
chunk_ids_vector, _ = vector_search(user_prompt, num_results=20, config=my_config)
chunk_ids_keyword, _ = keyword_search(user_prompt, num_results=20, config=my_config)
chunk_ids_hybrid, _ = hybrid_search(user_prompt, num_results=20, config=my_config)
chunk_ids_hybrid, _ = hybrid_search(
user_prompt, num_results=20, metadata_filter={"topic": "physics"}, config=my_config
) # Filter results to only include chunks from documents with topic="physics" (works with any search method)

# Retrieve chunks
from raglite import retrieve_chunks
Expand Down