vanna 2.0.1__py3-none-any.whl → 2.0.2__py3-none-any.whl

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.
@@ -16,6 +16,15 @@ try:
16
16
  from chromadb.config import Settings
17
17
  from chromadb.utils import embedding_functions
18
18
 
19
+ try:
20
+ from chromadb.errors import NotFoundError
21
+ except ImportError:
22
+ # Fallback for older ChromaDB versions that don't have chromadb.errors
23
+ class NotFoundError(Exception):
24
+ """Fallback NotFoundError for older ChromaDB versions."""
25
+
26
+ pass
27
+
19
28
  CHROMADB_AVAILABLE = True
20
29
  except ImportError:
21
30
  CHROMADB_AVAILABLE = False
@@ -31,7 +40,64 @@ from vanna.core.tool import ToolContext
31
40
 
32
41
 
33
42
  class ChromaAgentMemory(AgentMemory):
34
- """ChromaDB-based implementation of AgentMemory."""
43
+ """ChromaDB-based implementation of AgentMemory.
44
+
45
+ This implementation uses ChromaDB's PersistentClient to store agent memories
46
+ on disk, ensuring they persist across application restarts.
47
+
48
+ Key Features:
49
+ - Persistent storage: All memories are automatically saved to disk
50
+ - Efficient retrieval: Existing collections are loaded without re-initializing
51
+ embedding functions, avoiding unnecessary model downloads
52
+ - Flexible embedding: Supports custom embedding functions or uses ChromaDB's
53
+ default embedding function
54
+
55
+ Args:
56
+ persist_directory: Directory where ChromaDB will store its data.
57
+ Defaults to "./chroma_memory". Use an absolute path
58
+ for production deployments to ensure consistent location
59
+ across restarts.
60
+ collection_name: Name of the ChromaDB collection to use. Multiple agents
61
+ can share the same persist_directory with different
62
+ collection names.
63
+ embedding_function: Optional custom embedding function. If not provided,
64
+ ChromaDB's DefaultEmbeddingFunction is used (requires
65
+ internet connection on first use to download the model).
66
+ Once a collection is created, subsequent application
67
+ restarts will retrieve the existing collection without
68
+ re-downloading the model.
69
+
70
+ Example:
71
+ >>> from vanna.integrations.chromadb import ChromaAgentMemory
72
+ >>> # Basic usage with defaults
73
+ >>> memory = ChromaAgentMemory(
74
+ ... persist_directory="/app/data/chroma",
75
+ ... collection_name="my_agent_memory"
76
+ ... )
77
+ >>>
78
+ >>> # With custom embedding function (e.g., for offline use)
79
+ >>> from chromadb.utils import embedding_functions
80
+ >>> ef = embedding_functions.SentenceTransformerEmbeddingFunction()
81
+ >>> memory = ChromaAgentMemory(
82
+ ... persist_directory="/app/data/chroma",
83
+ ... embedding_function=ef
84
+ ... )
85
+
86
+ Note:
87
+ The default embedding function downloads an ONNX model (~80MB) on first use.
88
+ For air-gapped or offline environments, pre-download the model or provide
89
+ a custom embedding function.
90
+
91
+ Limitation:
92
+ This class does not validate that an existing Chroma collection was created
93
+ with the same embedding function as the one configured for the current
94
+ ``ChromaAgentMemory`` instance. If you reuse a collection (same
95
+ ``persist_directory`` and ``collection_name``) with a different embedding
96
+ function than was originally used, queries may fail or produce incorrect
97
+ similarity results. It is your responsibility to ensure that a given
98
+ collection is always accessed with a consistent embedding function, or to
99
+ implement your own validation around collection creation and reuse.
100
+ """
35
101
 
36
102
  def __init__(
37
103
  self,
@@ -76,12 +142,14 @@ class ChromaAgentMemory(AgentMemory):
76
142
  """Get or create ChromaDB collection."""
77
143
  if self._collection is None:
78
144
  client = self._get_client()
79
- embedding_func = self._get_embedding_function()
80
145
  try:
81
- self._collection = client.get_collection(
82
- name=self.collection_name, embedding_function=embedding_func
83
- )
84
- except Exception:
146
+ # Try to get existing collection first
147
+ # Don't pass embedding_function here to avoid re-instantiating/downloading it
148
+ # For existing collections, ChromaDB uses the stored embedding function configuration
149
+ self._collection = client.get_collection(name=self.collection_name)
150
+ except NotFoundError:
151
+ # Collection doesn't exist, create it with embedding function
152
+ embedding_func = self._get_embedding_function()
85
153
  self._collection = client.create_collection(
86
154
  name=self.collection_name,
87
155
  embedding_function=embedding_func,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vanna
3
- Version: 2.0.1
3
+ Version: 2.0.2
4
4
  Summary: Generate SQL queries from natural language
5
5
  Author-email: Zain Hoda <zain@vanna.ai>
6
6
  Requires-Python: >=3.9
@@ -128,7 +128,7 @@ vanna/integrations/azuresearch/agent_memory.py,sha256=zzGQmPOgrkLy5PA63joDa5Eprr
128
128
  vanna/integrations/bigquery/__init__.py,sha256=Sw-krShPv3nOLQIfVQSflCQWXqIQ-gF_eCuE6GHatNY,108
129
129
  vanna/integrations/bigquery/sql_runner.py,sha256=65CcGdX6kxOS5wUGSQ558w4_0oH412tV0f5jVwDczx0,2691
130
130
  vanna/integrations/chromadb/__init__.py,sha256=sPumYrf9hMVgEHh6rzXdWu9OrVkOucA5_HkQ4LXfIUY,3642
131
- vanna/integrations/chromadb/agent_memory.py,sha256=3s06jDc4v1m6MHSMLM3PKza9Em0Pm2hE6NMbGqD8HmU,14833
131
+ vanna/integrations/chromadb/agent_memory.py,sha256=nccMdv2VDrFkefw-hfKRLFUC_TgruApmKzR4T6lvBKo,18347
132
132
  vanna/integrations/clickhouse/__init__.py,sha256=Ke7P4HrHtgJZTfCnKv2P8flAS6IY-luZLtJCZmDlCig,114
133
133
  vanna/integrations/clickhouse/sql_runner.py,sha256=195z-Uij69AwyPOW3nO6ipjgGfA0oJ1TgxLcsGa7VtE,2350
134
134
  vanna/integrations/duckdb/__init__.py,sha256=kQiTv0Z5ozcIpL8FaZpZeYfxgbE6eteqIwjlbaqV4Ig,102
@@ -282,8 +282,8 @@ vanna/tools/run_sql.py,sha256=RGptT_cRfD6FP-3MnTS_pgYahWJbDSb3gv3yZ-5sR3g,6951
282
282
  vanna/tools/visualize_data.py,sha256=qgPMTxEAmbtJjb2j-qtAG1ZwtzvBvd8gdkzGMki_YGE,7551
283
283
  vanna/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
284
284
  vanna/web_components/__init__.py,sha256=QLzEJU3ersllv4pgZpaKdws3S3u5vDyTyUivawMc4A0,1040
285
- vanna-2.0.1.dist-info/entry_points.txt,sha256=lWU4rLAVNmrWnY6E66z_2TQW3QHU2Kzhwu2qvC6EBrs,62
286
- vanna-2.0.1.dist-info/licenses/LICENSE,sha256=VYiPMMDqj9BcxUkAYqrAzJpn5tCFXCrnglfRqS5l9Rk,1065
287
- vanna-2.0.1.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
288
- vanna-2.0.1.dist-info/METADATA,sha256=6eTDvS_ohU3WNtJwlBvGg1doY2hqDZmt7xnPjuV5Hrs,16519
289
- vanna-2.0.1.dist-info/RECORD,,
285
+ vanna-2.0.2.dist-info/entry_points.txt,sha256=lWU4rLAVNmrWnY6E66z_2TQW3QHU2Kzhwu2qvC6EBrs,62
286
+ vanna-2.0.2.dist-info/licenses/LICENSE,sha256=VYiPMMDqj9BcxUkAYqrAzJpn5tCFXCrnglfRqS5l9Rk,1065
287
+ vanna-2.0.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
288
+ vanna-2.0.2.dist-info/METADATA,sha256=Go4qGzf-AZrnvDZd0pPUJkfH_0U-v2qy08yRv1j5Uf8,16519
289
+ vanna-2.0.2.dist-info/RECORD,,
File without changes