Skip to content

Commit 3f238c3

Browse files
committed
Address code review feedback
1 parent dd172f2 commit 3f238c3

File tree

3 files changed

+9
-113
lines changed

3 files changed

+9
-113
lines changed

examples/typescript-sdk/context/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,4 @@ The auggie CLI respects both `.gitignore` and `.augmentignore` patterns and will
146146

147147
**Solution:** Run `auggie login` to authenticate, or set the `AUGMENT_API_TOKEN` and `AUGMENT_API_URL` environment variables.
148148

149-
### API Search Failures
150149

151-
**Problem:** Some searches return `"Retrieval failed. Please try again."`
152-
153-
**Cause:** Known issue with the staging API backend where certain query patterns consistently fail.
154-
155-
**Solution:** The Direct Context example includes automatic retry logic with exponential backoff. If queries still fail after retries, try rephrasing them:
156-
- ❌ "calculator functions for arithmetic" → ✅ "calculator functions"
157-
- ❌ "Calculator class methods" → ✅ "Calculator methods"
158-
159-
See [ISSUE_2_FINDINGS.md](./ISSUE_2_FINDINGS.md) for detailed analysis and failure patterns.

examples/typescript-sdk/context/direct-context/README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,4 @@ npx tsx examples/context/direct-context/index.ts
2626
- **`search()`**: Semantic search returning formatted code snippets
2727
- **`searchAndAsk()`**: One-step AI Q&A about indexed code
2828
- **State persistence**: Export/import index for reuse
29-
- **Retry logic**: Automatic retry with exponential backoff for failed searches
30-
31-
## Known Issues
32-
33-
### API Search Failures
34-
35-
Some search queries may fail with `"Retrieval failed. Please try again."` This is a known issue with the staging API backend. The example includes retry logic to handle these failures:
36-
37-
- Automatically retries failed searches up to 3 times
38-
- Uses exponential backoff (1s, 2s, 4s delays)
39-
- Logs retry attempts for visibility
40-
41-
**Workaround:** If a query consistently fails after retries, try rephrasing it:
42-
- ❌ "calculator functions for arithmetic" → ✅ "calculator functions"
43-
- ❌ "Calculator class methods" → ✅ "Calculator methods"
44-
45-
See [ISSUE_2_FINDINGS.md](../ISSUE_2_FINDINGS.md) for detailed analysis.
4629

examples/typescript-sdk/context/direct-context/index.ts

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -15,80 +15,6 @@ import { readFileSync } from "node:fs";
1515
import { join } from "node:path";
1616
import { DirectContext } from "@augmentcode/auggie-sdk";
1717

18-
/**
19-
* Retry a search operation with exponential backoff
20-
* This helps handle intermittent API failures
21-
*/
22-
async function searchWithRetry(
23-
context: DirectContext,
24-
query: string,
25-
maxRetries = 3
26-
): Promise<string> {
27-
const RETRY_MESSAGE = "Retrieval failed. Please try again.";
28-
29-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
30-
const result = await context.search(query);
31-
32-
// Check if the result indicates a failure
33-
if (result.includes(RETRY_MESSAGE)) {
34-
if (attempt < maxRetries) {
35-
const delay = Math.pow(2, attempt - 1) * 1000; // 1s, 2s, 4s
36-
console.log(` ⚠️ Search failed (attempt ${attempt}/${maxRetries}), retrying in ${delay}ms...`);
37-
await new Promise(resolve => setTimeout(resolve, delay));
38-
continue;
39-
} else {
40-
console.log(` ❌ Search failed after ${maxRetries} attempts`);
41-
return result; // Return the failure message
42-
}
43-
}
44-
45-
// Success
46-
if (attempt > 1) {
47-
console.log(` ✅ Search succeeded on attempt ${attempt}`);
48-
}
49-
return result;
50-
}
51-
52-
return RETRY_MESSAGE;
53-
}
54-
55-
/**
56-
* Retry a searchAndAsk operation with exponential backoff
57-
*/
58-
async function searchAndAskWithRetry(
59-
context: DirectContext,
60-
searchQuery: string,
61-
prompt: string,
62-
maxRetries = 3
63-
): Promise<string> {
64-
const RETRY_MESSAGE = "Retrieval failed. Please try again.";
65-
66-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
67-
const result = await context.searchAndAsk(searchQuery, prompt);
68-
69-
// Check if the result indicates a search failure
70-
if (result.includes(RETRY_MESSAGE)) {
71-
if (attempt < maxRetries) {
72-
const delay = Math.pow(2, attempt - 1) * 1000; // 1s, 2s, 4s
73-
console.log(` ⚠️ Search failed (attempt ${attempt}/${maxRetries}), retrying in ${delay}ms...`);
74-
await new Promise(resolve => setTimeout(resolve, delay));
75-
continue;
76-
} else {
77-
console.log(` ❌ Search failed after ${maxRetries} attempts`);
78-
return result; // Return the failure message
79-
}
80-
}
81-
82-
// Success
83-
if (attempt > 1) {
84-
console.log(` ✅ Search succeeded on attempt ${attempt}`);
85-
}
86-
return result;
87-
}
88-
89-
return RETRY_MESSAGE;
90-
}
91-
9218
async function main() {
9319
console.log("=== Direct Context Sample ===\n");
9420

@@ -416,23 +342,23 @@ export class HttpClient {
416342

417343
const result = await context.addToIndex(files);
418344
console.log("\nIndexing result:");
419-
console.log(" Newly indexed:", result.newlyIndexed);
420-
console.log(" Already indexed:", result.alreadyIndexed);
345+
console.log(" Newly uploaded:", result.newlyUploaded);
346+
console.log(" Already uploaded:", result.alreadyUploaded);
421347

422348
// Search the codebase - returns formatted string ready for LLM use or display
423349
// Using queries that work well with our realistic content
424350
console.log("\n--- Search 1: Find string utility functions ---");
425-
const results1 = await searchWithRetry(context, "string utility functions for text formatting");
351+
const results1 = await context.search("string utility functions for text formatting");
426352
console.log("Search results:");
427353
console.log(results1);
428354

429355
console.log("\n--- Search 2: Find user management service ---");
430-
const results2 = await searchWithRetry(context, "user management service with CRUD operations");
356+
const results2 = await context.search("user management service with CRUD operations");
431357
console.log("Search results:");
432358
console.log(results2);
433359

434360
console.log("\n--- Search 3: Find HTTP client for API requests ---");
435-
const httpResults = await searchWithRetry(context, "HTTP client for making API requests");
361+
const httpResults = await context.search("HTTP client for making API requests");
436362
console.log("Search results:");
437363
console.log(httpResults);
438364

@@ -441,8 +367,7 @@ export class HttpClient {
441367
const question = "How does the UserService class handle user creation and validation?";
442368
console.log(`Question: ${question}`);
443369

444-
const answer = await searchAndAskWithRetry(
445-
context,
370+
const answer = await context.searchAndAsk(
446371
"user creation and validation in UserService",
447372
question
448373
);
@@ -451,8 +376,7 @@ export class HttpClient {
451376

452377
// Use searchAndAsk to generate documentation
453378
console.log("\n--- searchAndAsk Example 2: Generate documentation ---");
454-
const documentation = await searchAndAskWithRetry(
455-
context,
379+
const documentation = await context.searchAndAsk(
456380
"string utility functions",
457381
"Generate API documentation in markdown format for the string utility functions"
458382
);
@@ -462,8 +386,7 @@ export class HttpClient {
462386

463387
// Use searchAndAsk to explain code patterns
464388
console.log("\n--- searchAndAsk Example 3: Explain code patterns ---");
465-
const explanation = await searchAndAskWithRetry(
466-
context,
389+
const explanation = await context.searchAndAsk(
467390
"utility functions",
468391
"Explain what these utility functions do and when they would be useful"
469392
);
@@ -487,7 +410,7 @@ export class HttpClient {
487410
console.log("State imported successfully");
488411

489412
// Verify we can still search
490-
const results3 = await searchWithRetry(context2, "string utility functions");
413+
const results3 = await context2.search("string utility functions");
491414
console.log("\nSearch after importing state:");
492415
console.log(results3);
493416

0 commit comments

Comments
 (0)