|
| 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() |
0 commit comments