Skip to content

Commit

Permalink
Use parameter object for retrieve function of Retriever (run-llama#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusschiesser authored Mar 7, 2024
1 parent de194d1 commit bf583a7
Show file tree
Hide file tree
Showing 50 changed files with 95 additions and 81 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-waves-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"llamaindex": minor
---

Use parameter object for retrieve function of Retriever (to align usage with query function of QueryEngine)
2 changes: 1 addition & 1 deletion apps/docs/docs/modules/node_postprocessors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const response = await queryEngine.query("<user_query>");
```ts
import { SimilarityPostprocessor } from "llamaindex";

nodes = await index.asRetriever().retrieve("test query str");
nodes = await index.asRetriever().retrieve({ query: "test query str" });

const processor = new SimilarityPostprocessor({
similarityCutoff: 0.7,
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/modules/retriever.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Fetch nodes!
const nodesWithScore = await retriever.retrieve("query string");
const nodesWithScore = await retriever.retrieve({ query: "query string" });
```

## API Reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// جلب العقد!
const nodesWithScore = await retriever.retrieve("سلسلة الاستعلام");
const nodesWithScore = await retriever.retrieve({ query: "سلسلة الاستعلام" });
```

## مرجع الواجهة البرمجية (API Reference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Извличане на върхове!
const nodesWithScore = await retriever.retrieve("query string");
const nodesWithScore = await retriever.retrieve({ query: "query string" });
```

## API Reference (API справка)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const recuperador = vector_index.asRetriever();
recuperador.similarityTopK = 3;

// Obteniu els nodes!
const nodesAmbPuntuació = await recuperador.retrieve("cadena de consulta");
const nodesAmbPuntuació = await recuperador.retrieve({ query: "cadena de consulta" });
```

## Referència de l'API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Získání uzlů!
const nodesWithScore = await retriever.retrieve("dotazovací řetězec");
const nodesWithScore = await retriever.retrieve({ query: "dotazovací řetězec" });
```

## API Reference (Odkazy na rozhraní)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Hent noder!
const nodesWithScore = await retriever.retrieve("forespørgselsstreng");
const nodesWithScore = await retriever.retrieve({ query: "forespørgselsstreng" });
```

## API Reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Knoten abrufen!
const nodesWithScore = await retriever.retrieve("Abfragezeichenfolge");
const nodesWithScore = await retriever.retrieve({ query: "Abfragezeichenfolge" });
```

## API-Referenz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Ανάκτηση κόμβων!
const nodesWithScore = await retriever.retrieve("συμβολοσειρά ερωτήματος");
const nodesWithScore = await retriever.retrieve({ query: "συμβολοσειρά ερωτήματος" });
```

## Αναφορά API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const recuperador = vector_index.asRetriever();
recuperador.similarityTopK = 3;

// ¡Obtener nodos!
const nodosConPuntuación = await recuperador.retrieve("cadena de consulta");
const nodosConPuntuación = await recuperador.retrieve({ query: "cadena de consulta" });
```

## Referencia de la API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Too sõlmed!
const nodesWithScore = await retriever.retrieve("päringu string");
const nodesWithScore = await retriever.retrieve({ query: "päringu string" });
```

## API viide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// بازیابی گره ها!
const nodesWithScore = await retriever.retrieve("رشته پرس و جو");
const nodesWithScore = await retriever.retrieve({ query: "رشته پرس و جو" });
```

## مرجع API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Hae solmut!
const nodesWithScore = await retriever.retrieve("kyselymerkkijono");
const nodesWithScore = await retriever.retrieve({ query: "kyselymerkkijono" });
```

## API-viite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Récupérer les nœuds !
const nodesWithScore = await retriever.retrieve("chaîne de requête");
const nodesWithScore = await retriever.retrieve({ query: "chaîne de requête" });
```

## Référence de l'API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// אחזור צמתים!
const nodesWithScore = await retriever.retrieve("מחרוזת שאילתה");
const nodesWithScore = await retriever.retrieve({ query: "מחרוזת שאילתה" });
```

## מדריך לממשק API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// नोड्स प्राप्त करें!
const nodesWithScore = await retriever.retrieve("क्वेरी स्ट्रिंग");
const nodesWithScore = await retriever.retrieve({ query: "क्वेरी स्ट्रिंग" });
```

## एपीआई संदर्भ (API Reference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const dohvatnik = vector_index.asRetriever();
dohvatnik.similarityTopK = 3;

// Dohvati čvorove!
const čvoroviSaRezultatom = await dohvatnik.retrieve("upitni niz");
const čvoroviSaRezultatom = await dohvatnik.retrieve({ query: "upitni niz" });
```

## API Referenca
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Node-ok lekérése!
const nodesWithScore = await retriever.retrieve("lekérdezési karakterlánc");
const nodesWithScore = await retriever.retrieve({ query: "lekérdezési karakterlánc" });
```

## API Referencia
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Mengambil node!
const nodesWithScore = await retriever.retrieve("string query");
const nodesWithScore = await retriever.retrieve({ query: "string query" });
```

## Referensi API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Recupera i nodi!
const nodesWithScore = await retriever.retrieve("stringa di query");
const nodesWithScore = await retriever.retrieve({ query: "stringa di query" });
```

## Riferimento API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// ノードを取得します!
const nodesWithScore = await retriever.retrieve("クエリ文字列");
const nodesWithScore = await retriever.retrieve({ query: "クエリ文字列" });
```

## API リファレンス
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// 노드를 가져옵니다!
const nodesWithScore = await retriever.retrieve("쿼리 문자열");
const nodesWithScore = await retriever.retrieve({ query: "쿼리 문자열" });
```

## API 참조
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const gavėjas = vector_index.asRetriever();
gavėjas.similarityTopK = 3;

// Išgaunami mazgai!
const mazgaiSuRezultatu = await gavėjas.retrieve("užklausos eilutė");
const mazgaiSuRezultatu = await gavėjas.retrieve({ query: "užklausos eilutė" });
```

## API nuorodos (API Reference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Haal knooppunten op!
const nodesWithScore = await retriever.retrieve("zoekopdracht");
const nodesWithScore = await retriever.retrieve({ query: "zoekopdracht" });
```

## API Referentie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Hent noder!
const nodesWithScore = await retriever.retrieve("spørringsstreng");
const nodesWithScore = await retriever.retrieve({ query: "spørringsstreng" });
```

## API-referanse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Pobierz węzły!
const nodesWithScore = await retriever.retrieve("ciąg zapytania");
const nodesWithScore = await retriever.retrieve({ query: "ciąg zapytania" });
```

## Dokumentacja interfejsu API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const recuperador = vector_index.asRetriever();
recuperador.similarityTopK = 3;

// Buscar nós!
const nósComPontuação = await recuperador.retrieve("string de consulta");
const nósComPontuação = await recuperador.retrieve({ query: "string de consulta" });
```

## Referência da API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const recuperator = vector_index.asRetriever();
recuperator.similarityTopK = 3;

// Preia nodurile!
const noduriCuScor = await recuperator.retrieve("șir de interogare");
const noduriCuScor = await recuperator.retrieve({ query: "șir de interogare" });
```

## Referință API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Получение узлов!
const nodesWithScore = await retriever.retrieve("строка запроса");
const nodesWithScore = await retriever.retrieve({ query: "строка запроса" });
```

## Справочник по API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Dohvati čvorove!
const nodesWithScore = await retriever.retrieve("upitni niz");
const nodesWithScore = await retriever.retrieve({ query: "upitni niz" });
```

## API Referenca
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const pridobitelj = vector_index.asRetriever();
pridobitelj.similarityTopK = 3;

// Pridobivanje vozlišč!
const vozliščaZRezultatom = await pridobitelj.retrieve("poizvedbeni niz");
const vozliščaZRezultatom = await pridobitelj.retrieve({ query: "poizvedbeni niz" });
```

## API Sklic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Získajte uzly!
const nodesWithScore = await retriever.retrieve("reťazec dotazu");
const nodesWithScore = await retriever.retrieve({ query: "reťazec dotazu" });
```

## API Referencia
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Hämta noder!
const nodesWithScore = await retriever.retrieve("frågesträng");
const nodesWithScore = await retriever.retrieve({ query: "frågesträng" });
```

## API-referens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// เรียกคืนโหนด!
const nodesWithScore = await retriever.retrieve("query string");
const nodesWithScore = await retriever.retrieve({ query: "query string" });
```

## API Reference (การอ้างอิง API)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Düğümleri getir!
const nodesWithScore = await retriever.retrieve("sorgu dizesi");
const nodesWithScore = await retriever.retrieve({ query: "sorgu dizesi" });
```

## API Referansı
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Отримати вузли!
const nodesWithScore = await retriever.retrieve("рядок запиту");
const nodesWithScore = await retriever.retrieve({ query: "рядок запиту" });
```

## Довідник API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// Lấy các node!
const nodesWithScore = await retriever.retrieve("chuỗi truy vấn");
const nodesWithScore = await retriever.retrieve({ query: "chuỗi truy vấn" });
```

## Tài liệu tham khảo API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// 获取节点!
const nodesWithScore = await retriever.retrieve("查询字符串");
const nodesWithScore = await retriever.retrieve({ query: "查询字符串" });
```

## API 参考
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
retriever.similarityTopK = 3;

// 提取節點!
const nodesWithScore = await retriever.retrieve("查詢字串");
const nodesWithScore = await retriever.retrieve({ query: "查詢字串" });
```

## API 參考
Expand Down
6 changes: 3 additions & 3 deletions examples/multimodal/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ async function main() {
// retrieve documents using the index
const index = await createIndex();
const retriever = index.asRetriever({ similarityTopK: 3 });
const results = await retriever.retrieve(
"what are Vincent van Gogh's famous paintings",
);
const results = await retriever.retrieve({
query: "what are Vincent van Gogh's famous paintings",
});
for (const result of results) {
const node = result.node;
if (!node) {
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/Retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import type { Event } from "./callbacks/CallbackManager.js";
import type { NodeWithScore } from "./Node.js";
import type { ServiceContext } from "./ServiceContext.js";

export type RetrieveParams = {
query: string;
parentEvent?: Event;
preFilters?: unknown;
};

/**
* Retrievers retrieve the nodes that most closely match our query in similarity.
*/
export interface BaseRetriever {
retrieve(
query: string,
parentEvent?: Event,
preFilters?: unknown,
): Promise<NodeWithScore[]>;
retrieve(params: RetrieveParams): Promise<NodeWithScore[]>;
getServiceContext(): ServiceContext;
}
Loading

0 comments on commit bf583a7

Please sign in to comment.