tavily-python 0.3.6__tar.gz → 0.3.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {tavily_python-0.3.6/tavily_python.egg-info → tavily_python-0.3.8}/PKG-INFO +4 -6
  2. {tavily_python-0.3.6 → tavily_python-0.3.8}/README.md +3 -5
  3. {tavily_python-0.3.6 → tavily_python-0.3.8}/setup.py +1 -1
  4. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily/__init__.py +2 -1
  5. tavily_python-0.3.8/tavily/hybrid_rag/__init__.py +1 -0
  6. tavily_python-0.3.6/tavily/hybrid_search/hybrid_search.py → tavily_python-0.3.8/tavily/hybrid_rag/hybrid_rag.py +40 -14
  7. {tavily_python-0.3.6 → tavily_python-0.3.8/tavily_python.egg-info}/PKG-INFO +4 -6
  8. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily_python.egg-info/SOURCES.txt +2 -2
  9. tavily_python-0.3.6/tavily/hybrid_search/__init__.py +0 -1
  10. {tavily_python-0.3.6 → tavily_python-0.3.8}/LICENSE +0 -0
  11. {tavily_python-0.3.6 → tavily_python-0.3.8}/setup.cfg +0 -0
  12. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily/async_tavily.py +0 -0
  13. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily/config.py +0 -0
  14. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily/errors.py +0 -0
  15. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily/tavily.py +0 -0
  16. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily/utils.py +0 -0
  17. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily_python.egg-info/dependency_links.txt +0 -0
  18. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily_python.egg-info/requires.txt +0 -0
  19. {tavily_python-0.3.6 → tavily_python-0.3.8}/tavily_python.egg-info/top_level.txt +0 -0
  20. {tavily_python-0.3.6 → tavily_python-0.3.8}/tests/test_async_search.py +0 -0
  21. {tavily_python-0.3.6 → tavily_python-0.3.8}/tests/test_sync_search.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tavily-python
3
- Version: 0.3.6
3
+ Version: 0.3.8
4
4
  Summary: Python wrapper for the Tavily API
5
5
  Home-page: https://github.com/tavily-ai/tavily-python
6
6
  Author: Tavily AI
@@ -89,18 +89,18 @@ Once you do so, you're ready to search the Web in one line of code! All you need
89
89
  ### Methods
90
90
  * **`search`**(query, **kwargs)
91
91
  * Performs a Tavily Search query and returns the response as a well-structured `dict`.
92
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`, `use_cache`.
92
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`.
93
93
  * **Returns** a `dict` with all related response fields. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `dict`. The details of the exact response format are given in the Search Responses section further down.
94
94
 
95
95
  * **`get_search_context`**(query, **kwargs)
96
96
  * Performs a Tavily Search query and returns a `str` of content and sources within the provided token limit. It's useful for getting only related content from retrieved websites without having to deal with context extraction and token management.
97
97
  * The **core parameter** for this function is `max_tokens`, an `int`. It defaults to `4000`. It is provided as a keyword argument.
98
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `use_cache`.
98
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`.
99
99
  * **Returns** a `str` containing the content and sources of the results. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
100
100
 
101
101
  * **`qna_search`**(query, **kwargs)
102
102
  * Performs a search and returns a string containing an answer to the original query. This is optimal to be used as a tool for AI agents.
103
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `max_results`, `include_domains`, `exclude_domains`, `use_cache`,
103
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `max_results`, `include_domains`, `exclude_domains`.
104
104
  * **Returns** a `str` containing a short answer to the search query. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
105
105
 
106
106
  ### Keyword Arguments (optional)
@@ -121,8 +121,6 @@ Once you do so, you're ready to search the Web in one line of code! All you need
121
121
 
122
122
  * **`exclude_domains`: list[str]** - A list of domains to specifically exclude from the search results. Default is `None`, which doesn't exclude any domains. Please note that this feature is only available when using the `"general"` search `topic`.
123
123
 
124
- * **`use_cache`: bool** - Use the cached web search results. Default is `True`. If `False` is passed, a new web search will be done before generating your search results.
125
-
126
124
  ### Search Responses
127
125
 
128
126
  * **`answer`: str**- The answer to your search query. This will be `None` unless `include_answer` is set to `True`.
@@ -72,18 +72,18 @@ Once you do so, you're ready to search the Web in one line of code! All you need
72
72
  ### Methods
73
73
  * **`search`**(query, **kwargs)
74
74
  * Performs a Tavily Search query and returns the response as a well-structured `dict`.
75
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`, `use_cache`.
75
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`.
76
76
  * **Returns** a `dict` with all related response fields. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `dict`. The details of the exact response format are given in the Search Responses section further down.
77
77
 
78
78
  * **`get_search_context`**(query, **kwargs)
79
79
  * Performs a Tavily Search query and returns a `str` of content and sources within the provided token limit. It's useful for getting only related content from retrieved websites without having to deal with context extraction and token management.
80
80
  * The **core parameter** for this function is `max_tokens`, an `int`. It defaults to `4000`. It is provided as a keyword argument.
81
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `use_cache`.
81
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`.
82
82
  * **Returns** a `str` containing the content and sources of the results. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
83
83
 
84
84
  * **`qna_search`**(query, **kwargs)
85
85
  * Performs a search and returns a string containing an answer to the original query. This is optimal to be used as a tool for AI agents.
86
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `max_results`, `include_domains`, `exclude_domains`, `use_cache`,
86
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `max_results`, `include_domains`, `exclude_domains`.
87
87
  * **Returns** a `str` containing a short answer to the search query. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
88
88
 
89
89
  ### Keyword Arguments (optional)
@@ -104,8 +104,6 @@ Once you do so, you're ready to search the Web in one line of code! All you need
104
104
 
105
105
  * **`exclude_domains`: list[str]** - A list of domains to specifically exclude from the search results. Default is `None`, which doesn't exclude any domains. Please note that this feature is only available when using the `"general"` search `topic`.
106
106
 
107
- * **`use_cache`: bool** - Use the cached web search results. Default is `True`. If `False` is passed, a new web search will be done before generating your search results.
108
-
109
107
  ### Search Responses
110
108
 
111
109
  * **`answer`: str**- The answer to your search query. This will be `None` unless `include_answer` is set to `True`.
@@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as f:
5
5
 
6
6
  setup(
7
7
  name='tavily-python',
8
- version='0.3.6',
8
+ version='0.3.8',
9
9
  url='https://github.com/tavily-ai/tavily-python',
10
10
  author='Tavily AI',
11
11
  author_email='support@tavily.com',
@@ -1,3 +1,4 @@
1
1
  from .async_tavily import AsyncTavilyClient
2
2
  from .tavily import Client, TavilyClient
3
- from .errors import InvalidAPIKeyError, UsageLimitExceededError, MissingAPIKeyError
3
+ from .errors import InvalidAPIKeyError, UsageLimitExceededError, MissingAPIKeyError
4
+ from .hybrid_rag import TavilyHybridClient
@@ -0,0 +1 @@
1
+ from .hybrid_rag import TavilyHybridClient
@@ -1,14 +1,14 @@
1
- '''
2
- WARNING
3
- Tavily Hybrid Search, as it is currently known internally, is a work-in-progress feature and may change in the future.
4
- Use at your own risk.
5
- '''
6
-
7
1
  import os
2
+ from typing import Union, Optional, Literal
3
+
4
+ from pymongo.collection import Collection
8
5
  from tavily import TavilyClient
9
- import cohere
10
6
 
11
- co = cohere.Client(os.getenv("COHERE_API_KEY"))
7
+ try:
8
+ import cohere
9
+ co = cohere.Client()
10
+ except:
11
+ co = None
12
12
 
13
13
  def _validate_index(client):
14
14
  """
@@ -68,8 +68,31 @@ def _cohere_rerank(query, documents, top_n):
68
68
  ]
69
69
 
70
70
  class TavilyHybridClient():
71
- def __init__(self, api_key, db_provider, collection, index, embeddings_field='embeddings',
72
- content_field='content'):
71
+ def __init__(
72
+ self,
73
+ api_key: Union[str, None],
74
+ db_provider: Literal['mongodb'],
75
+ collection: Collection,
76
+ index: str,
77
+ embeddings_field: str = 'embeddings',
78
+ content_field: str = 'content',
79
+ embedding_function: Optional[callable] = None,
80
+ ranking_function: Optional[callable] = None
81
+ ):
82
+ '''
83
+ A client for performing hybrid RAG using both the Tavily API and a local database collection.
84
+
85
+ Parameters:
86
+ api_key (str): The Tavily API key. If this is set to None, it will be loaded from the environment variable TAVILY_API_KEY.
87
+ db_provider (str): The database provider. Currently only 'mongodb' is supported.
88
+ collection (str): The name of the collection in the database that will be used for local search.
89
+ index (str): The name of the collection's vector search index.
90
+ embeddings_field (str): The name of the field in the collection that contains the embeddings.
91
+ content_field (str): The name of the field in the collection that contains the content.
92
+ embedding_function (callable): If provided, this function will be used to generate embeddings for the search query and documents.
93
+ ranking_function (callable): If provided, this function will be used to rerank the combined results.
94
+ '''
95
+
73
96
  self.tavily = TavilyClient(api_key)
74
97
 
75
98
  if db_provider != 'mongodb':
@@ -79,8 +102,9 @@ class TavilyHybridClient():
79
102
  self.index = index
80
103
  self.embeddings_field = embeddings_field
81
104
  self.content_field = content_field
82
- self.embedding_function = _cohere_embed
83
- self.ranking_function = _cohere_rerank
105
+
106
+ self.embedding_function = _cohere_embed if embedding_function is None else embedding_function
107
+ self.ranking_function = _cohere_rerank if ranking_function is None else ranking_function
84
108
 
85
109
  _validate_index(self)
86
110
 
@@ -124,7 +148,8 @@ class TavilyHybridClient():
124
148
  "content": f"${self.content_field}",
125
149
  "score": {
126
150
  "$meta": "vectorSearchScore"
127
- }
151
+ },
152
+ "origin": "local"
128
153
  }
129
154
  }
130
155
  ]))
@@ -139,7 +164,8 @@ class TavilyHybridClient():
139
164
  projected_foreign_results = [
140
165
  {
141
166
  'content': result['content'],
142
- 'score': result['score']
167
+ 'score': result['score'],
168
+ 'origin': 'foreign'
143
169
  }
144
170
  for result in foreign_results
145
171
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tavily-python
3
- Version: 0.3.6
3
+ Version: 0.3.8
4
4
  Summary: Python wrapper for the Tavily API
5
5
  Home-page: https://github.com/tavily-ai/tavily-python
6
6
  Author: Tavily AI
@@ -89,18 +89,18 @@ Once you do so, you're ready to search the Web in one line of code! All you need
89
89
  ### Methods
90
90
  * **`search`**(query, **kwargs)
91
91
  * Performs a Tavily Search query and returns the response as a well-structured `dict`.
92
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`, `use_cache`.
92
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`.
93
93
  * **Returns** a `dict` with all related response fields. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `dict`. The details of the exact response format are given in the Search Responses section further down.
94
94
 
95
95
  * **`get_search_context`**(query, **kwargs)
96
96
  * Performs a Tavily Search query and returns a `str` of content and sources within the provided token limit. It's useful for getting only related content from retrieved websites without having to deal with context extraction and token management.
97
97
  * The **core parameter** for this function is `max_tokens`, an `int`. It defaults to `4000`. It is provided as a keyword argument.
98
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`, `use_cache`.
98
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `max_results`, `include_domains`, `exclude_domains`.
99
99
  * **Returns** a `str` containing the content and sources of the results. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
100
100
 
101
101
  * **`qna_search`**(query, **kwargs)
102
102
  * Performs a search and returns a string containing an answer to the original query. This is optimal to be used as a tool for AI agents.
103
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `max_results`, `include_domains`, `exclude_domains`, `use_cache`,
103
+ * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `max_results`, `include_domains`, `exclude_domains`.
104
104
  * **Returns** a `str` containing a short answer to the search query. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
105
105
 
106
106
  ### Keyword Arguments (optional)
@@ -121,8 +121,6 @@ Once you do so, you're ready to search the Web in one line of code! All you need
121
121
 
122
122
  * **`exclude_domains`: list[str]** - A list of domains to specifically exclude from the search results. Default is `None`, which doesn't exclude any domains. Please note that this feature is only available when using the `"general"` search `topic`.
123
123
 
124
- * **`use_cache`: bool** - Use the cached web search results. Default is `True`. If `False` is passed, a new web search will be done before generating your search results.
125
-
126
124
  ### Search Responses
127
125
 
128
126
  * **`answer`: str**- The answer to your search query. This will be `None` unless `include_answer` is set to `True`.
@@ -8,8 +8,8 @@ tavily/config.py
8
8
  tavily/errors.py
9
9
  tavily/tavily.py
10
10
  tavily/utils.py
11
- tavily/hybrid_search/__init__.py
12
- tavily/hybrid_search/hybrid_search.py
11
+ tavily/hybrid_rag/__init__.py
12
+ tavily/hybrid_rag/hybrid_rag.py
13
13
  tavily_python.egg-info/PKG-INFO
14
14
  tavily_python.egg-info/SOURCES.txt
15
15
  tavily_python.egg-info/dependency_links.txt
@@ -1 +0,0 @@
1
- from .hybrid_search import TavilyHybridClient
File without changes
File without changes