Skip to content

Commit 21eedab

Browse files
committed
refactor(examples): restructure Python examples with dedicated directories
- Remove old advanced.py and custom_config.py files - Add new example structure with dedicated directories for basic, advanced, and custom_config examples - Each example now has its own README.md, main.py, and pyproject.toml - Update basic example to use from_content instead of from_text - Add proper configuration examples and documentation fix(python): improve IndexContext and Engine class naming - Rename from_text to from_content for better semantic meaning - Add explicit class names for Python bindings (IndexContext, QueryResult, DocumentInfo, Engine) - Update error handling with proper constructor - Fix module name from _vectorless to vectorless refactor(rust): update document format handling and builder logic - Remove Text format support temporarily - Set default format to Markdown instead of Text - Fix EngineBuilder to properly handle API key and model precedence - Update with_openai to not override existing model configuration - Improve documentation for builder methods
1 parent 007c66e commit 21eedab

19 files changed

Lines changed: 408 additions & 533 deletions

File tree

examples/python/advanced.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

examples/python/advanced/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Advanced Example - Full Configuration
2+
3+
Use a configuration file for fine-grained control.
4+
5+
## Setup
6+
7+
```bash
8+
pip install vectorless
9+
10+
# Copy the example config
11+
cp ../../../config.toml ./vectorless.toml
12+
13+
# Edit to customize your settings
14+
vim vectorless.toml
15+
```
16+
17+
## Run
18+
19+
```bash
20+
python main.py
21+
```
22+
23+
## Configuration File Structure
24+
25+
```toml
26+
[llm]
27+
api_key = "sk-..."
28+
29+
[llm.summary]
30+
model = "gpt-4o-mini"
31+
max_tokens = 200
32+
33+
[llm.retrieval]
34+
model = "gpt-4o"
35+
max_tokens = 100
36+
37+
[retrieval]
38+
top_k = 5
39+
beam_width = 3
40+
max_iterations = 10
41+
42+
[storage]
43+
workspace_dir = "./workspace"
44+
cache_size = 100
45+
```

examples/python/advanced/main.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Advanced example - Full Configuration File.
4+
5+
This example demonstrates how to use a full configuration file
6+
for fine-grained control over all settings.
7+
8+
Usage:
9+
cp ../../../config.toml ./vectorless.toml
10+
# Edit vectorless.toml to customize settings
11+
python main.py
12+
"""
13+
14+
import os
15+
from vectorless import Engine, IndexContext
16+
17+
# Path to config file (relative to this script)
18+
CONFIG_PATH = "./vectorless.toml"
19+
WORKSPACE = "./workspace"
20+
21+
22+
def main():
23+
print("=== Vectorless Advanced Example (Full Configuration) ===\n")
24+
25+
# Check if config file exists
26+
if not os.path.exists(CONFIG_PATH):
27+
print(f"Error: Config file not found: {CONFIG_PATH}")
28+
print("\nCreate it by copying the example:")
29+
print(f" cp ../../../config.toml {CONFIG_PATH}")
30+
print("\nThen edit it to customize your settings.")
31+
return
32+
33+
# Create engine with config file
34+
engine = Engine(config_path=CONFIG_PATH)
35+
36+
print(f"✓ Engine created with config file: {CONFIG_PATH}\n")
37+
38+
# Index a document
39+
content = """
40+
# System Documentation
41+
42+
## Architecture
43+
44+
The system consists of three main components:
45+
46+
1. **Index Pipeline** - Parses documents and builds a navigable tree
47+
2. **Retrieval Pipeline** - Queries and retrieves relevant content
48+
3. **Pilot** - LLM-powered navigation guide
49+
50+
## Configuration Options
51+
52+
### LLM Settings
53+
- `model`: The LLM model to use (e.g., "gpt-4o", "gpt-4o-mini")
54+
- `endpoint`: API endpoint URL
55+
- `api_key`: Your API key
56+
- `temperature`: Generation temperature (0.0 for deterministic)
57+
58+
### Retrieval Settings
59+
- `top_k`: Number of results to return
60+
- `max_iterations`: Maximum search iterations
61+
- `beam_width`: Beam width for multi-path search
62+
63+
### Storage Settings
64+
- `workspace_dir`: Directory for persisted documents
65+
- `cache_size`: LRU cache size
66+
- `compression`: Enable/disable compression
67+
68+
## Performance Tuning
69+
70+
For faster retrieval:
71+
- Use a smaller model like gpt-4o-mini
72+
- Reduce max_iterations
73+
- Enable caching
74+
75+
For higher accuracy:
76+
- Use a more capable model like gpt-4o
77+
- Increase beam_width
78+
- Enable multi-turn decomposition
79+
"""
80+
ctx = IndexContext.from_content(content, name="system_docs", format="markdown")
81+
doc_id = engine.index(ctx)
82+
print(f"✓ Indexed: {doc_id}\n")
83+
84+
# Query examples
85+
questions = [
86+
"What are the main components?",
87+
"How can I improve retrieval speed?",
88+
"What settings are available?",
89+
]
90+
91+
for q in questions:
92+
result = engine.query(doc_id, q)
93+
print(f"Q: {q}")
94+
print(f"A: {result.content[:150]}...")
95+
print(f" Score: {result.score:.2f}\n")
96+
97+
# Cleanup
98+
engine.remove(doc_id)
99+
print("✓ Cleaned up")
100+
101+
# Print configuration info
102+
print("\n" + "=" * 60)
103+
print("Configuration Priority")
104+
print("=" * 60)
105+
print("""
106+
1. Default configuration
107+
2. Auto-detected config file (vectorless.toml, config.toml)
108+
3. Explicit config file (config_path parameter)
109+
4. Environment variables (OPENAI_API_KEY, etc.)
110+
5. Constructor parameters (api_key, model, etc.)
111+
""")
112+
113+
114+
if __name__ == "__main__":
115+
main()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = "vectorless-advanced-example"
3+
version = "0.1.0"
4+
requires-python = ">=3.9"
5+
dependencies = [
6+
"vectorless",
7+
]
8+
9+
[build-system]
10+
requires = ["hatchling"]
11+
build-backend = "hatchling.build"

examples/python/basic/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Basic Example - Zero Configuration
2+
3+
The simplest way to use Vectorless.
4+
5+
## Setup
6+
7+
```bash
8+
pip install vectorless
9+
export OPENAI_API_KEY="sk-..."
10+
```
11+
12+
## Run
13+
14+
```bash
15+
python main.py
16+
```
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2026 vectorless developers
3-
# SPDX-License-Identifier: Apache-2.0
4-
52
"""
6-
Basic usage example - Zero Configuration.
3+
Basic example - Zero Configuration.
74
85
This example demonstrates the simplest way to use Vectorless.
96
Just set OPENAI_API_KEY environment variable and you're ready to go.
107
118
Usage:
129
export OPENAI_API_KEY="sk-..."
13-
python basic.py
10+
python main.py
1411
"""
1512

1613
import os
@@ -22,7 +19,6 @@ def main():
2219
print("=== Vectorless Basic Example (Zero Configuration) ===\n")
2320

2421
# Zero configuration: Just set OPENAI_API_KEY environment variable
25-
# The engine will automatically use it.
2622
with tempfile.TemporaryDirectory() as workspace:
2723
engine = Engine(workspace=workspace)
2824

@@ -56,7 +52,7 @@ def main():
5652
print(result.content)
5753
```
5854
"""
59-
ctx = IndexContext.from_text(content, name="manual", format="markdown")
55+
ctx = IndexContext.from_content(content, name="manual", format="markdown")
6056
doc_id = engine.index(ctx)
6157
print(f"✓ Indexed: {doc_id}\n")
6258

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = "vectorless-basic-example"
3+
version = "0.1.0"
4+
requires-python = ">=3.9"
5+
dependencies = [
6+
"vectorless",
7+
]
8+
9+
[build-system]
10+
requires = ["hatchling"]
11+
build-backend = "hatchling.build"

0 commit comments

Comments
 (0)