(
startUrl: string,
vector: number[],
nRetrieve: number,
isRetry: boolean = false,
)
| 822 | } |
| 823 | // This function attempts to retrieve chunks by vector similarity |
| 824 | async retrieveChunks( |
| 825 | startUrl: string, |
| 826 | vector: number[], |
| 827 | nRetrieve: number, |
| 828 | isRetry: boolean = false, |
| 829 | ): Promise<Chunk[]> { |
| 830 | // Get the appropriate embeddings provider |
| 831 | const { provider } = await this.getEmbeddingsProvider(); |
| 832 | if (!provider) { |
| 833 | return []; |
| 834 | } |
| 835 | |
| 836 | // Lance doesn't have an embeddingsprovider column, instead it includes it in the table name |
| 837 | const table = await this.getOrCreateLanceTable({ |
| 838 | initializationVector: vector, |
| 839 | startUrl, |
| 840 | }); |
| 841 | |
| 842 | let docs: LanceDbDocsRow[] = []; |
| 843 | try { |
| 844 | docs = await table |
| 845 | .search(vector) |
| 846 | .limit(nRetrieve) |
| 847 | .where(`starturl = '${startUrl}'`) |
| 848 | .execute(); |
| 849 | } catch (e: any) { |
| 850 | console.warn("Error retrieving chunks from LanceDB", e); |
| 851 | } |
| 852 | |
| 853 | return docs.map(this.lanceDBRowToChunk); |
| 854 | } |
| 855 | |
| 856 | async getIndexedPages(startUrl: string): Promise<Set<string>> { |
| 857 | try { |
no test coverage detected