(feat/extract) Refactor and Reranker improvements (#1100)
* Reapply "Nick: extract api reference"
This reverts commit 61d7ba76f7.
* Nick: refactor analyzer
* Nick: formatting
* Nick:
* Update extraction-service.ts
* Nick: fixes
* NIck:
* Nick: wip
* Nick: reverted to the old re-ranker
* Nick:
* Update extract-status.ts
This commit is contained in:
@@ -40,5 +40,68 @@ to determine their relevance to the user's query and intent.
|
||||
}
|
||||
|
||||
export function buildRerankerUserPrompt(searchQuery: string): string {
|
||||
return `Given these URLs, rank which ones are relevant to the user's extraction intent: "${searchQuery}".`;
|
||||
return `Given these URLs and their content, identify which ones are relevant to the user's extraction request: "${searchQuery}". Return an array of relevant links with their relevance scores (0-1). Higher scores should be given to URLs that directly address the user's extraction request. Be very mindful with the links you select, as if they are not that relevant it may affect the quality of the extraction. Only include URLs that have a relvancy score of 0.6+.`;
|
||||
}
|
||||
|
||||
// Multi entity schema anlayzer
|
||||
export function buildAnalyzeSchemaPrompt(): string {
|
||||
return `You are a query classifier for a web scraping system. Classify the data extraction query as either:
|
||||
A) Single-Answer: One answer across a few pages, possibly containing small arrays.
|
||||
B) Multi-Entity: Many items across many pages, often involving large arrays.
|
||||
|
||||
Consider:
|
||||
1. Answer Cardinality: Single or multiple items?
|
||||
2. Page Distribution: Found on 1-3 pages or many?
|
||||
3. Verification Needs: Cross-page verification or independent extraction?
|
||||
|
||||
Provide:
|
||||
- Method: [Single-Answer/Multi-Entity]
|
||||
- Confidence: [0-100%]
|
||||
- Reasoning: Why this classification?
|
||||
- Key Indicators: Specific aspects leading to this decision.
|
||||
|
||||
Examples:
|
||||
- "Is this company a non-profit?" -> Single-Answer
|
||||
- "Extract all product prices" -> Multi-Entity
|
||||
|
||||
For Single-Answer, arrays may be present but are typically small. For Multi-Entity, if arrays have multiple items not from a single page, return keys with large arrays. If nested, return the full key (e.g., 'ecommerce.products').`;
|
||||
}
|
||||
|
||||
export function buildAnalyzeSchemaUserPrompt(
|
||||
schemaString: string,
|
||||
prompt: string,
|
||||
urls: string[],
|
||||
): string {
|
||||
return `Classify the query as Single-Answer or Multi-Entity. For Multi-Entity, return keys with large arrays; otherwise, return none:
|
||||
Schema: ${schemaString}\nPrompt: ${prompt}\nRelevant URLs: ${urls}`;
|
||||
}
|
||||
|
||||
// Should Extract
|
||||
|
||||
export function buildShouldExtractSystemPrompt(): string {
|
||||
return `You are a content relevance checker. Your job is to determine if the provided content is very relevant to extract information from based on the user's prompt. Return true only if the content appears relevant and contains information that could help answer the prompt. Return false if the content seems irrelevant or unlikely to contain useful information for the prompt.`;
|
||||
}
|
||||
|
||||
export function buildShouldExtractUserPrompt(
|
||||
prompt: string,
|
||||
schema: any,
|
||||
): string {
|
||||
return `Should the following content be used to extract information for this prompt: "${prompt}" User schema is: ${JSON.stringify(schema)}\nReturn only true or false.`;
|
||||
}
|
||||
|
||||
// Batch extract
|
||||
export function buildBatchExtractSystemPrompt(
|
||||
systemPrompt: string,
|
||||
multiEntitySchema: any,
|
||||
links: string[],
|
||||
): string {
|
||||
return (
|
||||
(systemPrompt ? `${systemPrompt}\n` : "") +
|
||||
`Always prioritize using the provided content to answer the question. Do not make up an answer. Do not hallucinate. Be concise and follow the schema always if provided. If the document provided is not relevant to the prompt nor to the final user schema ${JSON.stringify(multiEntitySchema)}, return null. Here are the urls the user provided of which he wants to extract information from: ` +
|
||||
links.join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
export function buildBatchExtractPrompt(prompt: string): string {
|
||||
return `Today is: ${new Date().toISOString()}\n${prompt}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user