Skip to content

Commit 3755204

Browse files
committed
Docs updates to clarify optimize usage.
1 parent 0a0ed4d commit 3755204

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎docs/src/content/docs/optimization.mdx‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,19 @@ Optimization can significantly improve accuracy on real-world tasks:
7474

7575
## Persisting Results
7676

77-
Saving/loading an optimized extractor is not yet implemented.
78-
For now, re-run `optimize()` when you start up, or persist your training data and configuration.
77+
Save and load optimized extractors to reuse them without re-running optimization:
78+
79+
```python
80+
# Save after optimization
81+
extractor.save("./my_extractor")
82+
83+
# Load later
84+
from langstruct import LangStruct
85+
loaded = LangStruct.load("./my_extractor")
86+
87+
# Use immediately - optimization is preserved
88+
result = loaded.extract("new text")
89+
```
7990

8091
## Advanced (If You Need It)
8192

@@ -110,25 +121,25 @@ extractor.optimize(
110121
## Common Questions
111122

112123
**Q: Do I always need training data?**
113-
A: No! Optimization can work without training data, but providing examples improves results significantly.
124+
A: You need example texts, but not necessarily expected outputs. If you don't provide `expected_results`, LangStruct uses the LLM's confidence ratings to optimize. Providing expected outputs significantly improves accuracy.
114125

115126
**Q: How long does optimization take?**
116127
A: Usually 1-5 minutes for typical datasets (10-100 examples).
117128

118129
**Q: Can I optimize an already optimized extractor?**
119-
A: Yes! You can keep optimizing with new data as you get it.
130+
A: Yes, you can continue optimizing with new data as you collect it.
120131

121132
**Q: Will this make my extractions slower?**
122-
A: No - optimization happens once during training. Production extraction speed is the same.
133+
A: No - optimization happens once during training. Production extraction speed is unchanged.
123134

124135
**Q: What happens when I switch models?**
125-
A: Just change the model and re-optimize! Same training data, same accuracy - zero prompt rewriting needed.
136+
A: Change the model and re-optimize with the same training data. No prompt rewriting needed.
126137

127138
## Next Steps
128139

129140
<CardGrid>
130141
<Card title="Try It Now" icon="laptop">
131-
Create a LangStruct extractor and enable optimization when you need accuracy!
142+
Create a LangStruct extractor and enable optimization when you need accuracy.
132143
</Card>
133144
<Card title="Source Grounding" icon="document">
134145
[Track where information comes from](/source-grounding/)

‎docs/src/content/docs/quickstart.mdx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ extractor = LangStruct(example=schema)
8787
# See optimization in action
8888
extractor.optimize(
8989
texts=["training texts..."],
90-
expected=[{"expected outputs..."}]
90+
expected_results=[{"expected outputs..."}] # Optional - uses confidence if omitted
9191
)
92-
print(f"Optimized accuracy: {extractor.score:.1%}")
9392
```
9493

9594
## Process Multiple Documents (with quotas)

‎docs/src/content/docs/why-dspy.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ extractor = LangStruct(example={
119119

120120
# 2. Let MIPROv2 optimize prompts and examples automatically
121121
extractor.optimize(
122-
training_texts=["Apple reported $125B in Q3...", "Meta earned $40B..."],
122+
texts=["Apple reported $125B in Q3...", "Meta earned $40B..."],
123123
expected_results=[
124124
{"company": "Apple", "revenue": 125.0, "quarter": "Q3"},
125125
{"company": "Meta", "revenue": 40.0, "quarter": "Q3"}
@@ -148,15 +148,15 @@ extractor = LangStruct(
148148
example={"company": "Apple", "revenue": 100.0},
149149
model="gpt-5-mini",
150150
)
151-
extractor.optimize(training_texts, expected_results)
151+
extractor.optimize(texts=training_texts, expected_results=expected_results)
152152

153153
# 6 months later, switch to Claude - just two lines!
154154
extractor.model = "claude-3-7-sonnet-latest"
155-
extractor.optimize(training_texts, expected_results) # Auto-reoptimizes prompts
155+
extractor.optimize(texts=training_texts, expected_results=expected_results) # Auto-reoptimizes prompts
156156

157157
# Or use local models for privacy
158158
extractor.model = "ollama/llama3.2"
159-
extractor.optimize(training_texts, expected_results) # Works the same way
159+
extractor.optimize(texts=training_texts, expected_results=expected_results) # Works the same way
160160

161161
# Same accuracy, zero prompt rewriting, zero vendor lock-in
162162
```

0 commit comments

Comments
 (0)