initial commit: slides + practica_resueltos + README
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
---
|
||||
layout: default
|
||||
---
|
||||
|
||||
# Consumir reranker self-hosted desde Node.js
|
||||
|
||||
<v-clicks>
|
||||
|
||||
No hay integración oficial con LangChain.js, pero la API REST es muy sencilla:
|
||||
|
||||
```typescript
|
||||
async function rerank(query: string, docs: string[], topN = 3) {
|
||||
const res = await fetch("http://localhost:7997/rerank", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ query, documents: docs }),
|
||||
});
|
||||
const results = await res.json();
|
||||
// [{ index: 2, relevance_score: 0.95 }, { index: 0, relevance_score: 0.72 }, ...]
|
||||
|
||||
return results
|
||||
.sort((a, b) => b.relevance_score - a.relevance_score)
|
||||
.slice(0, topN);
|
||||
}
|
||||
|
||||
// Uso con documentos de LangChain
|
||||
const searchResults = await vectorStore.similaritySearch(query, 10);
|
||||
const ranked = await rerank(query, searchResults.map(d => d.pageContent));
|
||||
const topDocs = ranked.map(r => searchResults[r.index]);
|
||||
```
|
||||
|
||||
<div class="mt-4 p-4 bg-blue-500/10 rounded">
|
||||
💡 Misma API para Infinity y TEI — cambiar de runtime no requiere cambiar código
|
||||
</div>
|
||||
|
||||
</v-clicks>
|
||||
Reference in New Issue
Block a user