vectorwave 0.2.7__tar.gz → 0.2.9__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.
- vectorwave-0.2.9/PKG-INFO +255 -0
- vectorwave-0.2.9/Readme.md +226 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/pyproject.toml +4 -2
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/decorator.py +51 -4
- vectorwave-0.2.9/src/vectorwave/database/db.py +309 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/database/db_search.py +15 -26
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/models/db_config.py +18 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/tracer.py +75 -130
- vectorwave-0.2.9/src/vectorwave/utils/github_pr.py +87 -0
- vectorwave-0.2.9/src/vectorwave/utils/healer.py +330 -0
- vectorwave-0.2.9/src/vectorwave/utils/path_utils.py +32 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/utils/return_caching_utils.py +18 -7
- vectorwave-0.2.9/src/vectorwave/utils/scheduler.py +127 -0
- vectorwave-0.2.7/PKG-INFO +0 -60
- vectorwave-0.2.7/Readme.md +0 -33
- vectorwave-0.2.7/src/vectorwave/database/db.py +0 -413
- vectorwave-0.2.7/src/vectorwave/utils/healer.py +0 -155
- {vectorwave-0.2.7 → vectorwave-0.2.9}/crates/Cargo.lock +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/crates/Cargo.toml +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/crates/src/lib.rs +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/batch/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/batch/batch.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/auto_injector.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/core.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/generator.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/llm/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/llm/base.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/llm/factory.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/core/llm/openai_client.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/database/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/database/archiver.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/database/dataset.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/exception/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/exception/exceptions.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/models/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/alert/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/alert/base.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/alert/factory.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/alert/null_alerter.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/alert/webhook_alerter.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/monitoring/monitoring.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/prediction/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/prediction/predictor.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/search/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/search/execution_search.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/search/extended_search.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/search/rag_search.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/utils/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/utils/context.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/utils/function_cache.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/utils/replayer.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/utils/replayer_semantic.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/utils/status.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/vectorizer/__init__.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/vectorizer/base.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/vectorizer/factory.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/vectorizer/huggingface_vectorizer.py +0 -0
- {vectorwave-0.2.7 → vectorwave-0.2.9}/src/vectorwave/vectorizer/openai_vectorizer.py +0 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vectorwave
|
|
3
|
+
Version: 0.2.9
|
|
4
|
+
Classifier: Programming Language :: Python :: 3
|
|
5
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
9
|
+
Classifier: Programming Language :: Rust
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Requires-Dist: weaviate-client>=4.0.0
|
|
14
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
15
|
+
Requires-Dist: sentence-transformers
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Requires-Dist: openai
|
|
18
|
+
Requires-Dist: pygithub
|
|
19
|
+
Requires-Dist: schedule
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
License-File: NOTICE
|
|
22
|
+
Summary: VectorWave: Seamless Auto-Vectorization Framework
|
|
23
|
+
Author-email: junyeonggim <junyeonggim5@gmail.com>
|
|
24
|
+
License-Expression: MIT
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
27
|
+
Project-URL: Repository, https://github.com/cozymori/vectorwave
|
|
28
|
+
|
|
29
|
+
Need more information? Visit [here](https://cozymori.github.io/vectorwave-docs/)
|
|
30
|
+
|
|
31
|
+
# VectorWave
|
|
32
|
+

|
|
33
|
+

|
|
34
|
+

|
|
35
|
+

|
|
36
|
+

|
|
37
|
+

|
|
38
|
+

|
|
39
|
+

|
|
40
|
+

|
|
41
|
+
<br>**Seamless Auto-Vectorization Framework**
|
|
42
|
+
|
|
43
|
+
We transform volatile data that disappears the moment code is executed into a Searchable and Reusable permanent knowledge asset.
|
|
44
|
+
|
|
45
|
+
### Requirements
|
|
46
|
+
|
|
47
|
+
* **Python**: 3.10 ~ 3.13
|
|
48
|
+
* **Docker**: Required to run the Weaviate database.
|
|
49
|
+
* (Optional) **OpenAI API Key**: Required for AI auto-documentation and high-performance embedding.
|
|
50
|
+
|
|
51
|
+
### How to reach us
|
|
52
|
+
|
|
53
|
+
Have questions or found a bug? Please join our community.
|
|
54
|
+
|
|
55
|
+
* **GitHub Issues**: [https://github.com/cozymori/vectorwave/issues](https://github.com/cozymori/vectorwave/issues)
|
|
56
|
+
|
|
57
|
+
### Contributors
|
|
58
|
+
[See the contributors of vectorwave](https://github.com/Cozymori/VectorWave/graphs/contributors)<br>
|
|
59
|
+
VectorWave is an open-source project and we welcome your contributions.
|
|
60
|
+
Please refer to [CONTRIBUTING.md](https://www.google.com/search?q=https://github.com/cozymori/vectorwave/blob/main/CONTRIBUTING.md) in the GitHub repository.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🚀 What is VectorWave?
|
|
65
|
+
|
|
66
|
+
**VectorWave** is a unified framework designed to solve the "Efficiency vs. Reliability" dilemma in LLM-integrated applications. It introduces a new paradigm of **Execution-Level Semantic Optimization** combined with **Autonomous Self-Healing**.
|
|
67
|
+
|
|
68
|
+
Unlike conventional semantic caching tools that primarily focus on text similarity, **VectorWave** captures the entire **Function Execution Context**. It creates a permanent "Golden Dataset" from your successful executions and uses it to:
|
|
69
|
+
|
|
70
|
+
1. **Slash Costs**: Serve cached results for semantically similar inputs, bypassing expensive computations.
|
|
71
|
+
2. **Fix Bugs**: Automatically diagnose runtime errors and generate GitHub PRs using LLM.
|
|
72
|
+
3. **Monitor Quality**: Detect when user inputs start drifting away from known patterns (Semantic Drift).
|
|
73
|
+
|
|
74
|
+
## Architecture
|
|
75
|
+
|
|
76
|
+
VectorWave operates as a transparent layer between your application and the LLM/Infrastructure, handling everything from vectorization to GitOps automation.
|
|
77
|
+
|
|
78
|
+

|
|
79
|
+
|
|
80
|
+
### Core Components
|
|
81
|
+
* **Optimization Engine**: Intercepts function calls to check for semantic cache hits using HNSW indexes.
|
|
82
|
+
* **Trace Context Manager**: Collects execution logs, inputs, and outputs without modifying your code structure.
|
|
83
|
+
* **Self-Healing Pipeline**: An autonomous agent that wakes up on errors, diagnoses the root cause, and submits patches.
|
|
84
|
+
|
|
85
|
+
## 😊 Quick Start
|
|
86
|
+
|
|
87
|
+
You can attach VectorWave to any Python function using a simple decorator.
|
|
88
|
+
|
|
89
|
+
### 1. Prerequisites (Start Vector DB)
|
|
90
|
+
|
|
91
|
+
VectorWave requires a Vector Database (Weaviate) to store execution contexts.
|
|
92
|
+
Create a `docker-compose.yml` file and start the service:
|
|
93
|
+
|
|
94
|
+
```yaml
|
|
95
|
+
# docker-compose.yml
|
|
96
|
+
version: '3.4'
|
|
97
|
+
services:
|
|
98
|
+
weaviate:
|
|
99
|
+
command:
|
|
100
|
+
- --host
|
|
101
|
+
- 0.0.0.0
|
|
102
|
+
- --port
|
|
103
|
+
- '8080'
|
|
104
|
+
- --scheme
|
|
105
|
+
- http
|
|
106
|
+
image: semitechnologies/weaviate:1.26.1
|
|
107
|
+
ports:
|
|
108
|
+
- 8080:8080
|
|
109
|
+
- 50051:50051
|
|
110
|
+
restart: on-failure:0
|
|
111
|
+
environment:
|
|
112
|
+
QUERY_DEFAULTS_LIMIT: 25
|
|
113
|
+
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
|
|
114
|
+
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
|
|
115
|
+
DEFAULT_VECTORIZER_MODULE: 'none'
|
|
116
|
+
ENABLE_MODULES: 'text2vec-openai,generative-openai'
|
|
117
|
+
CLUSTER_HOSTNAME: 'node1'
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Run the container:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
docker-compose up -d
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 2. Install VectorWave
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pip install vectorwave
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### 3. Basic Usage (Semantic Caching)
|
|
136
|
+
|
|
137
|
+
Now, apply the `@vectorize` decorator to your functions.
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
import time
|
|
141
|
+
from vectorwave import vectorize, initialize_database
|
|
142
|
+
|
|
143
|
+
# 1. (Optional) Set up your OpenAI Key for vectorization
|
|
144
|
+
# os.environ["OPENAI_API_KEY"] = "sk-..."
|
|
145
|
+
|
|
146
|
+
initialize_database()
|
|
147
|
+
|
|
148
|
+
# 2. Just add the @vectorize decorator!
|
|
149
|
+
@vectorize(semantic_cache=True, cache_threshold=0.95, auto=True)
|
|
150
|
+
def expensive_llm_task(query: str):
|
|
151
|
+
# Simulate a slow and expensive API call
|
|
152
|
+
time.sleep(2)
|
|
153
|
+
return f"Processed result for: {query}"
|
|
154
|
+
|
|
155
|
+
# First call: Runs the function (Cache Miss) -> Took 2.0s
|
|
156
|
+
print(expensive_llm_task("How do I fix a Python bug?"))
|
|
157
|
+
|
|
158
|
+
# Second call: Returns from Weaviate DB (Cache Hit) -> Took 0.02s!
|
|
159
|
+
# Even if the query is slightly different but semantically same.
|
|
160
|
+
print(expensive_llm_task("Tell me how to debug Python code."))
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 4. Self-Healing in Action
|
|
165
|
+
|
|
166
|
+
When your code breaks, VectorWave actively fixes it.
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
# Suppose this function has a bug (ZeroDivisionError)
|
|
170
|
+
@vectorize(auto=True)
|
|
171
|
+
def risky_calculation(a, b):
|
|
172
|
+
return a / b
|
|
173
|
+
|
|
174
|
+
# Triggering an error
|
|
175
|
+
risky_calculation(10, 0)
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**What happens next?**
|
|
180
|
+
|
|
181
|
+
1. **Detection**: The `AutoHealerBot` detects the `ZeroDivisionError`.
|
|
182
|
+
2. **Diagnosis**: It retrieves the source code and error stack trace.
|
|
183
|
+
3. **Fix**: It uses an LLM to generate a patch (adding `try-except` or input validation).
|
|
184
|
+
4. **Action**: A **Pull Request** is automatically created in your GitHub repository.
|
|
185
|
+
|
|
186
|
+

|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
## Key Features
|
|
190
|
+
|
|
191
|
+
### ⚡ Optimization Engine (Semantic Caching)
|
|
192
|
+
|
|
193
|
+
Don't pay for the same computation twice. VectorWave uses **Weaviate** vector database to store and retrieve function results based on meaning, not just exact string matching.
|
|
194
|
+
|
|
195
|
+
* **Latency**: Reduced from seconds to milliseconds.
|
|
196
|
+
* **Cost**: Up to 90% reduction in LLM token usage.
|
|
197
|
+
|
|
198
|
+

|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
### Self-Healing & GitOps
|
|
202
|
+
|
|
203
|
+
VectorWave doesn't just log errors; it acts on them.
|
|
204
|
+
|
|
205
|
+
* **Automated Root Cause Analysis (RCA)** using RAG.
|
|
206
|
+
* **GitOps Integration**: Generates actual code fixes and pushes them to a new branch.
|
|
207
|
+
* **Cooldown Mechanism**: Prevents spamming PRs for the same error.
|
|
208
|
+
|
|
209
|
+
### Semantic Drift Radar
|
|
210
|
+
|
|
211
|
+
Detect when your users are asking things your model wasn't designed for.
|
|
212
|
+
|
|
213
|
+
* **Anomaly Detection**: Calculates the distance between new queries and your "Golden Dataset".
|
|
214
|
+
* **Alerting**: Sends notifications (e.g., Discord) when drift exceeds the threshold (default 0.25).
|
|
215
|
+
|
|
216
|
+

|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
## How does it work?
|
|
220
|
+
|
|
221
|
+
Unlike traditional Key-Value caching (e.g., Redis), VectorWave understands **Context**.
|
|
222
|
+
|
|
223
|
+
1. **Vectorization**: It converts function arguments into high-dimensional vectors using OpenAI or HuggingFace models.
|
|
224
|
+
2. **Search**: It performs an Approximate Nearest Neighbor (ANN) search in the vector store.
|
|
225
|
+
3. **Decision**:
|
|
226
|
+
* If a neighbor is found within the `threshold` -> **Return Cached Result**.
|
|
227
|
+
* If not -> **Execute Function** -> **Async Log to DB**.
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
## Performance Benchmark
|
|
232
|
+
|
|
233
|
+
| Metric | Direct Execution | With VectorWave | Improvement |
|
|
234
|
+
| --- | --- | --- | --- |
|
|
235
|
+
| **Latency (Hit)** | ~2.5s (LLM API) | **~0.02s** | **125x Faster** |
|
|
236
|
+
| **Cost (Hit)** | $0.03 / call | **$0.00** | **100% Savings** |
|
|
237
|
+
| **Reliability** | Manual Fix Required | **Auto-PR Created** | **Autonomous** |
|
|
238
|
+
|
|
239
|
+
## Feature Comparison
|
|
240
|
+
|
|
241
|
+
Why choose VectorWave over traditional semantic caches?
|
|
242
|
+
|
|
243
|
+
| Feature | Traditional Tools (e.g., GPTCache) | **VectorWave** |
|
|
244
|
+
| :--- | :---: | :---: |
|
|
245
|
+
| **Semantic Caching** | O (Text-based) | **O (Execution Context)** |
|
|
246
|
+
| **Self-Healing (Auto-Fix)** | X | **O (Autonomous)** |
|
|
247
|
+
| **GitOps (Auto-PR)** | X | **O (Seamless)** |
|
|
248
|
+
| **Semantic Drift Detection** | X | **O (Drift Radar)** |
|
|
249
|
+
| **Zero-Config Setup** | △ (Setup Required) | **O (Decorator)** |
|
|
250
|
+
|
|
251
|
+
## 😍 Contributing
|
|
252
|
+
|
|
253
|
+
We are extremely open to contributions! Whether it's a new vectorizer, a better healing prompt, or just a typo fix.
|
|
254
|
+
Please check our [Contribution Guide](./Contributing.md).
|
|
255
|
+
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Need more information? Visit [here](https://cozymori.github.io/vectorwave-docs/)
|
|
2
|
+
|
|
3
|
+
# VectorWave
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
<br>**Seamless Auto-Vectorization Framework**
|
|
14
|
+
|
|
15
|
+
We transform volatile data that disappears the moment code is executed into a Searchable and Reusable permanent knowledge asset.
|
|
16
|
+
|
|
17
|
+
### Requirements
|
|
18
|
+
|
|
19
|
+
* **Python**: 3.10 ~ 3.13
|
|
20
|
+
* **Docker**: Required to run the Weaviate database.
|
|
21
|
+
* (Optional) **OpenAI API Key**: Required for AI auto-documentation and high-performance embedding.
|
|
22
|
+
|
|
23
|
+
### How to reach us
|
|
24
|
+
|
|
25
|
+
Have questions or found a bug? Please join our community.
|
|
26
|
+
|
|
27
|
+
* **GitHub Issues**: [https://github.com/cozymori/vectorwave/issues](https://github.com/cozymori/vectorwave/issues)
|
|
28
|
+
|
|
29
|
+
### Contributors
|
|
30
|
+
[See the contributors of vectorwave](https://github.com/Cozymori/VectorWave/graphs/contributors)<br>
|
|
31
|
+
VectorWave is an open-source project and we welcome your contributions.
|
|
32
|
+
Please refer to [CONTRIBUTING.md](https://www.google.com/search?q=https://github.com/cozymori/vectorwave/blob/main/CONTRIBUTING.md) in the GitHub repository.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 What is VectorWave?
|
|
37
|
+
|
|
38
|
+
**VectorWave** is a unified framework designed to solve the "Efficiency vs. Reliability" dilemma in LLM-integrated applications. It introduces a new paradigm of **Execution-Level Semantic Optimization** combined with **Autonomous Self-Healing**.
|
|
39
|
+
|
|
40
|
+
Unlike conventional semantic caching tools that primarily focus on text similarity, **VectorWave** captures the entire **Function Execution Context**. It creates a permanent "Golden Dataset" from your successful executions and uses it to:
|
|
41
|
+
|
|
42
|
+
1. **Slash Costs**: Serve cached results for semantically similar inputs, bypassing expensive computations.
|
|
43
|
+
2. **Fix Bugs**: Automatically diagnose runtime errors and generate GitHub PRs using LLM.
|
|
44
|
+
3. **Monitor Quality**: Detect when user inputs start drifting away from known patterns (Semantic Drift).
|
|
45
|
+
|
|
46
|
+
## Architecture
|
|
47
|
+
|
|
48
|
+
VectorWave operates as a transparent layer between your application and the LLM/Infrastructure, handling everything from vectorization to GitOps automation.
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
### Core Components
|
|
53
|
+
* **Optimization Engine**: Intercepts function calls to check for semantic cache hits using HNSW indexes.
|
|
54
|
+
* **Trace Context Manager**: Collects execution logs, inputs, and outputs without modifying your code structure.
|
|
55
|
+
* **Self-Healing Pipeline**: An autonomous agent that wakes up on errors, diagnoses the root cause, and submits patches.
|
|
56
|
+
|
|
57
|
+
## 😊 Quick Start
|
|
58
|
+
|
|
59
|
+
You can attach VectorWave to any Python function using a simple decorator.
|
|
60
|
+
|
|
61
|
+
### 1. Prerequisites (Start Vector DB)
|
|
62
|
+
|
|
63
|
+
VectorWave requires a Vector Database (Weaviate) to store execution contexts.
|
|
64
|
+
Create a `docker-compose.yml` file and start the service:
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
# docker-compose.yml
|
|
68
|
+
version: '3.4'
|
|
69
|
+
services:
|
|
70
|
+
weaviate:
|
|
71
|
+
command:
|
|
72
|
+
- --host
|
|
73
|
+
- 0.0.0.0
|
|
74
|
+
- --port
|
|
75
|
+
- '8080'
|
|
76
|
+
- --scheme
|
|
77
|
+
- http
|
|
78
|
+
image: semitechnologies/weaviate:1.26.1
|
|
79
|
+
ports:
|
|
80
|
+
- 8080:8080
|
|
81
|
+
- 50051:50051
|
|
82
|
+
restart: on-failure:0
|
|
83
|
+
environment:
|
|
84
|
+
QUERY_DEFAULTS_LIMIT: 25
|
|
85
|
+
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
|
|
86
|
+
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
|
|
87
|
+
DEFAULT_VECTORIZER_MODULE: 'none'
|
|
88
|
+
ENABLE_MODULES: 'text2vec-openai,generative-openai'
|
|
89
|
+
CLUSTER_HOSTNAME: 'node1'
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Run the container:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
docker-compose up -d
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 2. Install VectorWave
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install vectorwave
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 3. Basic Usage (Semantic Caching)
|
|
108
|
+
|
|
109
|
+
Now, apply the `@vectorize` decorator to your functions.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import time
|
|
113
|
+
from vectorwave import vectorize, initialize_database
|
|
114
|
+
|
|
115
|
+
# 1. (Optional) Set up your OpenAI Key for vectorization
|
|
116
|
+
# os.environ["OPENAI_API_KEY"] = "sk-..."
|
|
117
|
+
|
|
118
|
+
initialize_database()
|
|
119
|
+
|
|
120
|
+
# 2. Just add the @vectorize decorator!
|
|
121
|
+
@vectorize(semantic_cache=True, cache_threshold=0.95, auto=True)
|
|
122
|
+
def expensive_llm_task(query: str):
|
|
123
|
+
# Simulate a slow and expensive API call
|
|
124
|
+
time.sleep(2)
|
|
125
|
+
return f"Processed result for: {query}"
|
|
126
|
+
|
|
127
|
+
# First call: Runs the function (Cache Miss) -> Took 2.0s
|
|
128
|
+
print(expensive_llm_task("How do I fix a Python bug?"))
|
|
129
|
+
|
|
130
|
+
# Second call: Returns from Weaviate DB (Cache Hit) -> Took 0.02s!
|
|
131
|
+
# Even if the query is slightly different but semantically same.
|
|
132
|
+
print(expensive_llm_task("Tell me how to debug Python code."))
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 4. Self-Healing in Action
|
|
137
|
+
|
|
138
|
+
When your code breaks, VectorWave actively fixes it.
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
# Suppose this function has a bug (ZeroDivisionError)
|
|
142
|
+
@vectorize(auto=True)
|
|
143
|
+
def risky_calculation(a, b):
|
|
144
|
+
return a / b
|
|
145
|
+
|
|
146
|
+
# Triggering an error
|
|
147
|
+
risky_calculation(10, 0)
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**What happens next?**
|
|
152
|
+
|
|
153
|
+
1. **Detection**: The `AutoHealerBot` detects the `ZeroDivisionError`.
|
|
154
|
+
2. **Diagnosis**: It retrieves the source code and error stack trace.
|
|
155
|
+
3. **Fix**: It uses an LLM to generate a patch (adding `try-except` or input validation).
|
|
156
|
+
4. **Action**: A **Pull Request** is automatically created in your GitHub repository.
|
|
157
|
+
|
|
158
|
+

|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## Key Features
|
|
162
|
+
|
|
163
|
+
### ⚡ Optimization Engine (Semantic Caching)
|
|
164
|
+
|
|
165
|
+
Don't pay for the same computation twice. VectorWave uses **Weaviate** vector database to store and retrieve function results based on meaning, not just exact string matching.
|
|
166
|
+
|
|
167
|
+
* **Latency**: Reduced from seconds to milliseconds.
|
|
168
|
+
* **Cost**: Up to 90% reduction in LLM token usage.
|
|
169
|
+
|
|
170
|
+

|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
### Self-Healing & GitOps
|
|
174
|
+
|
|
175
|
+
VectorWave doesn't just log errors; it acts on them.
|
|
176
|
+
|
|
177
|
+
* **Automated Root Cause Analysis (RCA)** using RAG.
|
|
178
|
+
* **GitOps Integration**: Generates actual code fixes and pushes them to a new branch.
|
|
179
|
+
* **Cooldown Mechanism**: Prevents spamming PRs for the same error.
|
|
180
|
+
|
|
181
|
+
### Semantic Drift Radar
|
|
182
|
+
|
|
183
|
+
Detect when your users are asking things your model wasn't designed for.
|
|
184
|
+
|
|
185
|
+
* **Anomaly Detection**: Calculates the distance between new queries and your "Golden Dataset".
|
|
186
|
+
* **Alerting**: Sends notifications (e.g., Discord) when drift exceeds the threshold (default 0.25).
|
|
187
|
+
|
|
188
|
+

|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
## How does it work?
|
|
192
|
+
|
|
193
|
+
Unlike traditional Key-Value caching (e.g., Redis), VectorWave understands **Context**.
|
|
194
|
+
|
|
195
|
+
1. **Vectorization**: It converts function arguments into high-dimensional vectors using OpenAI or HuggingFace models.
|
|
196
|
+
2. **Search**: It performs an Approximate Nearest Neighbor (ANN) search in the vector store.
|
|
197
|
+
3. **Decision**:
|
|
198
|
+
* If a neighbor is found within the `threshold` -> **Return Cached Result**.
|
|
199
|
+
* If not -> **Execute Function** -> **Async Log to DB**.
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
## Performance Benchmark
|
|
204
|
+
|
|
205
|
+
| Metric | Direct Execution | With VectorWave | Improvement |
|
|
206
|
+
| --- | --- | --- | --- |
|
|
207
|
+
| **Latency (Hit)** | ~2.5s (LLM API) | **~0.02s** | **125x Faster** |
|
|
208
|
+
| **Cost (Hit)** | $0.03 / call | **$0.00** | **100% Savings** |
|
|
209
|
+
| **Reliability** | Manual Fix Required | **Auto-PR Created** | **Autonomous** |
|
|
210
|
+
|
|
211
|
+
## Feature Comparison
|
|
212
|
+
|
|
213
|
+
Why choose VectorWave over traditional semantic caches?
|
|
214
|
+
|
|
215
|
+
| Feature | Traditional Tools (e.g., GPTCache) | **VectorWave** |
|
|
216
|
+
| :--- | :---: | :---: |
|
|
217
|
+
| **Semantic Caching** | O (Text-based) | **O (Execution Context)** |
|
|
218
|
+
| **Self-Healing (Auto-Fix)** | X | **O (Autonomous)** |
|
|
219
|
+
| **GitOps (Auto-PR)** | X | **O (Seamless)** |
|
|
220
|
+
| **Semantic Drift Detection** | X | **O (Drift Radar)** |
|
|
221
|
+
| **Zero-Config Setup** | △ (Setup Required) | **O (Decorator)** |
|
|
222
|
+
|
|
223
|
+
## 😍 Contributing
|
|
224
|
+
|
|
225
|
+
We are extremely open to contributions! Whether it's a new vectorizer, a better healing prompt, or just a typo fix.
|
|
226
|
+
Please check our [Contribution Guide](./Contributing.md).
|
|
@@ -5,7 +5,7 @@ build-backend = "maturin"
|
|
|
5
5
|
|
|
6
6
|
[project]
|
|
7
7
|
name = "vectorwave"
|
|
8
|
-
version = "0.2.
|
|
8
|
+
version = "0.2.09"
|
|
9
9
|
authors = [
|
|
10
10
|
{ name = "junyeonggim", email = "junyeonggim5@gmail.com" },
|
|
11
11
|
]
|
|
@@ -30,7 +30,9 @@ dependencies = [
|
|
|
30
30
|
"pydantic-settings>=2.0.0",
|
|
31
31
|
"sentence-transformers",
|
|
32
32
|
"requests",
|
|
33
|
-
"openai"
|
|
33
|
+
"openai",
|
|
34
|
+
"PyGithub",
|
|
35
|
+
"schedule"
|
|
34
36
|
]
|
|
35
37
|
|
|
36
38
|
[project.urls]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import logging
|
|
3
|
+
import os
|
|
3
4
|
from functools import wraps
|
|
4
5
|
from typing import List, Optional, Dict, Any
|
|
5
6
|
|
|
@@ -12,6 +13,7 @@ from ..utils.function_cache import function_cache_manager
|
|
|
12
13
|
from ..utils.return_caching_utils import _check_and_return_cached_result
|
|
13
14
|
from ..vectorizer.factory import get_vectorizer
|
|
14
15
|
from ..utils.context import execution_source_context
|
|
16
|
+
from ..utils.path_utils import get_repo_root_and_relative_path # New import
|
|
15
17
|
|
|
16
18
|
logger = logging.getLogger(__name__)
|
|
17
19
|
|
|
@@ -26,6 +28,9 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
26
28
|
cache_threshold: float = 0.9,
|
|
27
29
|
replay: bool = False,
|
|
28
30
|
attributes_to_capture: Optional[List[str]] = None,
|
|
31
|
+
capture_inputs: bool = False,
|
|
32
|
+
semantic_cache_filters: Optional[Dict[str, Any]] = None,
|
|
33
|
+
semantic_cache_scope: Optional[List[str]] = None,
|
|
29
34
|
**execution_tags):
|
|
30
35
|
"""
|
|
31
36
|
VectorWave Decorator with Auto-Generation support.
|
|
@@ -60,6 +65,15 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
60
65
|
if attr not in final_attributes:
|
|
61
66
|
final_attributes.append(attr)
|
|
62
67
|
|
|
68
|
+
if capture_inputs:
|
|
69
|
+
try:
|
|
70
|
+
sig = inspect.signature(func)
|
|
71
|
+
for param_name in sig.parameters:
|
|
72
|
+
if param_name not in ('self', 'cls') and param_name not in final_attributes:
|
|
73
|
+
final_attributes.append(param_name)
|
|
74
|
+
except Exception as e:
|
|
75
|
+
logger.warning(f"Failed to inspect signature for auto-capture in '{function_name}': {e}")
|
|
76
|
+
|
|
63
77
|
if replay:
|
|
64
78
|
try:
|
|
65
79
|
sig = inspect.signature(func)
|
|
@@ -90,8 +104,22 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
90
104
|
docstring = inspect.getdoc(func) or ""
|
|
91
105
|
source_code = inspect.getsource(func)
|
|
92
106
|
|
|
107
|
+
try:
|
|
108
|
+
abs_file_path = os.path.abspath(inspect.getsourcefile(func))
|
|
109
|
+
repo_root, relative_file_path = get_repo_root_and_relative_path(abs_file_path)
|
|
110
|
+
if relative_file_path:
|
|
111
|
+
file_path = relative_file_path
|
|
112
|
+
else:
|
|
113
|
+
file_path = abs_file_path # Fallback to absolute path if not in a git repo
|
|
114
|
+
logger.warning(f"Function '{function_name}' is not in a Git repository. "
|
|
115
|
+
f"PR creation might fail for absolute path: {file_path}")
|
|
116
|
+
except Exception as e:
|
|
117
|
+
file_path = ""
|
|
118
|
+
logger.error(f"Failed to determine file path for '{function_name}': {e}")
|
|
119
|
+
|
|
93
120
|
static_properties = {
|
|
94
121
|
"function_name": function_name,
|
|
122
|
+
"file_path": file_path,
|
|
95
123
|
"module_name": module_name,
|
|
96
124
|
"docstring": docstring,
|
|
97
125
|
"source_code": source_code,
|
|
@@ -109,7 +137,6 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
109
137
|
"static_properties": static_properties
|
|
110
138
|
})
|
|
111
139
|
else:
|
|
112
|
-
# [Existing] Immediate Registration Mode
|
|
113
140
|
current_content_hash = function_cache_manager.calculate_content_hash(func_identifier, static_properties)
|
|
114
141
|
|
|
115
142
|
if function_cache_manager.is_cached_and_unchanged(func_uuid, current_content_hash):
|
|
@@ -137,6 +164,25 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
137
164
|
except Exception as e:
|
|
138
165
|
logger.error("Error in @vectorize setup for '%s': %s", func.__name__, e)
|
|
139
166
|
|
|
167
|
+
def resolve_semantic_filters(args, kwargs):
|
|
168
|
+
runtime_filters = semantic_cache_filters.copy() if semantic_cache_filters else {}
|
|
169
|
+
|
|
170
|
+
if semantic_cache_scope:
|
|
171
|
+
try:
|
|
172
|
+
sig = inspect.signature(func)
|
|
173
|
+
bound_args = sig.bind(*args, **kwargs)
|
|
174
|
+
bound_args.apply_defaults()
|
|
175
|
+
|
|
176
|
+
for arg_name in semantic_cache_scope:
|
|
177
|
+
if arg_name in bound_args.arguments:
|
|
178
|
+
runtime_filters[arg_name] = bound_args.arguments[arg_name]
|
|
179
|
+
else:
|
|
180
|
+
logger.warning(f"Semantic Scope: Argument '{arg_name}' not found in call to '{function_name}'.")
|
|
181
|
+
except Exception as e:
|
|
182
|
+
logger.error(f"Failed to resolve semantic_cache_scope for '{function_name}': {e}")
|
|
183
|
+
|
|
184
|
+
return runtime_filters
|
|
185
|
+
|
|
140
186
|
# --- Wrapper Logic ---
|
|
141
187
|
|
|
142
188
|
if is_async_func:
|
|
@@ -144,7 +190,6 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
144
190
|
@trace_span(attributes_to_capture=final_attributes, capture_return_value=capture_return_value)
|
|
145
191
|
@wraps(func)
|
|
146
192
|
async def inner_wrapper(*args, **kwargs):
|
|
147
|
-
# Remove injected tags from kwargs before calling original func
|
|
148
193
|
clean_kwargs = {k: v for k, v in kwargs.items() if
|
|
149
194
|
k not in valid_execution_tags and k != 'function_uuid' and k != 'exec_source'}
|
|
150
195
|
return await func(*args, **clean_kwargs)
|
|
@@ -152,7 +197,8 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
152
197
|
@wraps(func)
|
|
153
198
|
async def outer_wrapper(*args, **kwargs):
|
|
154
199
|
if semantic_cache:
|
|
155
|
-
|
|
200
|
+
filters = resolve_semantic_filters(args, kwargs)
|
|
201
|
+
cached = _check_and_return_cached_result(func, args, kwargs, function_name, cache_threshold, True, filters=filters)
|
|
156
202
|
if cached is not None: return cached
|
|
157
203
|
|
|
158
204
|
full_kwargs = kwargs.copy()
|
|
@@ -176,7 +222,8 @@ def vectorize(search_description: Optional[str] = None,
|
|
|
176
222
|
@wraps(func)
|
|
177
223
|
def outer_wrapper(*args, **kwargs):
|
|
178
224
|
if semantic_cache:
|
|
179
|
-
|
|
225
|
+
filters = resolve_semantic_filters(args, kwargs)
|
|
226
|
+
cached = _check_and_return_cached_result(func, args, kwargs, function_name, cache_threshold, False, filters=filters)
|
|
180
227
|
if cached is not None: return cached
|
|
181
228
|
|
|
182
229
|
full_kwargs = kwargs.copy()
|