R2R supports multiple Embedding providers, offering flexibility in choosing and switching between different models based on your specific requirements. This guide provides an in-depth look at configuring and using various Embedding providers within the R2R framework.
For a quick start on basic configuration, including embedding setup, please refer to our configuration guide.
from r2r import R2Rapp = R2R()# Ingest a file, which will use the configured embedding modelresponse = app.ingest_files(["path/to/your/file.txt"])print(f"Ingestion response: {response}")
# Perform a search, which will embed the query using the configured modelsearch_results = app.search("Your search query here")print(f"Search results: {search_results}")
# Update existing files, which may involve re-embeddingupdate_response = app.update_files(["path/to/updated/file.txt"])print(f"Update response: {update_response}")
Remember that you don’t directly call the embedding methods in your application code. R2R handles the embedding process internally based on your configuration.
You can create custom embedding providers by inheriting from the EmbeddingProvider class and implementing the required methods. This allows you to integrate any embedding model or service into R2R.
Update the EmbeddingConfig class to include your custom provider:
Copy
Ask AI
class EmbeddingConfig(ProviderConfig): # ...existing code... @property def supported_providers(self) -> list[str]: return [None, "openai", "ollama", "sentence-transformers", "custom"] # Add your custom provider here
Update your R2R configuration to use the custom provider:
Copy
Ask AI
[embedding]provider = "custom"base_model = "your-custom-model"base_dimension = 768batch_size = 32[embedding.prefixes]index = "Represent this document for retrieval: "query = "Represent this query for retrieving relevant documents: "
In your R2R application, register the custom provider:
Copy
Ask AI
from r2r import R2Rfrom r2r.base import EmbeddingConfigfrom your_module import CustomEmbeddingProviderdef get_embedding_provider(config: EmbeddingConfig): if config.provider == "custom": return CustomEmbeddingProvider(config) # ... handle other providers ...r2r = R2R(embedding_provider_factory=get_embedding_provider)
Now you can use your custom Embedding provider seamlessly within your R2R application:
Copy
Ask AI
# Ingest documents (embeddings will be generated using your custom provider)r2r.ingest_files(["path/to/document.txt"])# Perform a searchresults = r2r.search("Your search query")# Use RAGrag_response = r2r.rag("Your question here")
By following this structure, you can integrate any embedding model or service into R2R, maintaining consistency with the existing system while adding custom functionality as needed. This approach allows for great flexibility in choosing or implementing embedding solutions that best fit your specific use case.### Embedding Prefixes
R2R’s Embedding system provides a flexible and powerful foundation for integrating various embedding models into your applications. By understanding the available providers, configuration options, and best practices, you can effectively leverage embeddings to enhance your R2R-based projects.
For an advanced example of implementing reranking in R2R.
Assistant
Responses are generated using AI and may contain mistakes.
R2R supports multiple Embedding providers, offering flexibility in choosing and switching between different models based on your specific requirements. This guide provides an in-depth look at configuring and using various Embedding providers within the R2R framework.
For a quick start on basic configuration, including embedding setup, please refer to our configuration guide.
from r2r import R2Rapp = R2R()# Ingest a file, which will use the configured embedding modelresponse = app.ingest_files(["path/to/your/file.txt"])print(f"Ingestion response: {response}")
# Perform a search, which will embed the query using the configured modelsearch_results = app.search("Your search query here")print(f"Search results: {search_results}")
# Update existing files, which may involve re-embeddingupdate_response = app.update_files(["path/to/updated/file.txt"])print(f"Update response: {update_response}")
Remember that you don’t directly call the embedding methods in your application code. R2R handles the embedding process internally based on your configuration.
You can create custom embedding providers by inheriting from the EmbeddingProvider class and implementing the required methods. This allows you to integrate any embedding model or service into R2R.
Update the EmbeddingConfig class to include your custom provider:
Copy
Ask AI
class EmbeddingConfig(ProviderConfig): # ...existing code... @property def supported_providers(self) -> list[str]: return [None, "openai", "ollama", "sentence-transformers", "custom"] # Add your custom provider here
Update your R2R configuration to use the custom provider:
Copy
Ask AI
[embedding]provider = "custom"base_model = "your-custom-model"base_dimension = 768batch_size = 32[embedding.prefixes]index = "Represent this document for retrieval: "query = "Represent this query for retrieving relevant documents: "
In your R2R application, register the custom provider:
Copy
Ask AI
from r2r import R2Rfrom r2r.base import EmbeddingConfigfrom your_module import CustomEmbeddingProviderdef get_embedding_provider(config: EmbeddingConfig): if config.provider == "custom": return CustomEmbeddingProvider(config) # ... handle other providers ...r2r = R2R(embedding_provider_factory=get_embedding_provider)
Now you can use your custom Embedding provider seamlessly within your R2R application:
Copy
Ask AI
# Ingest documents (embeddings will be generated using your custom provider)r2r.ingest_files(["path/to/document.txt"])# Perform a searchresults = r2r.search("Your search query")# Use RAGrag_response = r2r.rag("Your question here")
By following this structure, you can integrate any embedding model or service into R2R, maintaining consistency with the existing system while adding custom functionality as needed. This approach allows for great flexibility in choosing or implementing embedding solutions that best fit your specific use case.### Embedding Prefixes
R2R’s Embedding system provides a flexible and powerful foundation for integrating various embedding models into your applications. By understanding the available providers, configuration options, and best practices, you can effectively leverage embeddings to enhance your R2R-based projects.
For an advanced example of implementing reranking in R2R.
Assistant
Responses are generated using AI and may contain mistakes.