{ "cells": [ { "cell_type": "markdown", "source": [ "# How to use MongoDB with LinkML-Store\n", "\n", "LinkML-Store provides a uniform interface across different backends. It allows you to write database-neutral code\n", "and operations where it makes sense, and use database-specific code where you need it.\n", "\n", "The best supported backend is duckdb. The next best is MongoDB.\n", "\n", "This tutorial walks through using MongoDB via the Python interface. It is recommended you start first with the main\n", "tutorial.\n", "\n" ], "metadata": { "collapsed": false }, "id": "fc4794dd116ed21" }, { "cell_type": "markdown", "source": [ "## Creating a client and attaching to a database\n", "\n", "First we will create a client as normal:" ], "metadata": { "collapsed": false }, "id": "493c7599d2f40c27" }, { "cell_type": "code", "execution_count": 1, "outputs": [], "source": [ "from linkml_store import Client\n", "\n", "client = Client()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.350753Z", "start_time": "2024-06-23T01:28:16.554178Z" } }, "id": "initial_id" }, { "cell_type": "markdown", "source": [ "Next we'll attach to a MongoDB instance. this assumes you have one running already." ], "metadata": { "collapsed": false }, "id": "470f1cb70bf3641b" }, { "cell_type": "code", "execution_count": 2, "outputs": [], "source": [ "db = client.attach_database(\"mongodb://localhost:27017\", \"test\")" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.354666Z", "start_time": "2024-06-23T01:28:18.351799Z" } }, "id": "cc164c0acbe4c39d" }, { "cell_type": "code", "execution_count": 3, "outputs": [ { "data": { "text/plain": "'mongodb://localhost:27017'" }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.handle" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.359736Z", "start_time": "2024-06-23T01:28:18.355122Z" } }, "id": "cb437a6dd0f73ec8" }, { "cell_type": "code", "execution_count": 4, "outputs": [ { "data": { "text/plain": "'{\"handle\":\"mongodb://localhost:27017\",\"alias\":\"test\",\"schema_location\":null,\"schema_dict\":null,\"collections\":{},\"recreate_if_exists\":false,\"collection_type_slot\":null,\"searchable_slots\":null,\"ensure_referential_integrity\":false}'" }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db.metadata.model_dump_json()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.364131Z", "start_time": "2024-06-23T01:28:18.360436Z" } }, "id": "4390916095bf647a" }, { "cell_type": "markdown", "source": [ "## Creating a collection\n", "\n", "We'll create a simple test collection. The concept of collection in linkml-store maps directly to mongodb collections" ], "metadata": { "collapsed": false }, "id": "334ea2ced79828f7" }, { "cell_type": "code", "execution_count": 5, "outputs": [], "source": [ "collection = db.create_collection(\"test\", recreate_if_exists=True)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.402657Z", "start_time": "2024-06-23T01:28:18.366296Z" } }, "id": "c3a79013f9359a9" }, { "cell_type": "markdown", "source": [ "## Preparing data to load" ], "metadata": { "collapsed": false }, "id": "207f35ee61edc14d" }, { "cell_type": "markdown", "source": [ "Next we'll parse an (incomplete) list of countries in JSON-Lines format:" ], "metadata": { "collapsed": false }, "id": "9c6277c067fef8c7" }, { "cell_type": "code", "execution_count": 6, "outputs": [], "source": [ "COUNTRIES = \"../../tests/input/countries/countries.jsonl\"" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.407892Z", "start_time": "2024-06-23T01:28:18.392332Z" } }, "id": "5286ef4e9dd0f316" }, { "cell_type": "code", "execution_count": 7, "outputs": [], "source": [ "from linkml_store.utils.format_utils import load_objects\n", "\n", "objects = load_objects(COUNTRIES)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.408181Z", "start_time": "2024-06-23T01:28:18.394820Z" } }, "id": "2e21988e4fc13f58" }, { "cell_type": "markdown", "source": [ "Let's check with pandas just to make sure it looks as expected:" ], "metadata": { "collapsed": false }, "id": "90e2e9793375431f" }, { "cell_type": "code", "execution_count": 8, "outputs": [ { "data": { "text/plain": " name code capital continent \\\n0 United States US Washington, D.C. North America \n1 Canada CA Ottawa North America \n2 Mexico MX Mexico City North America \n3 Brazil BR Brasília South America \n4 Argentina AR Buenos Aires South America \n5 United Kingdom GB London Europe \n6 France FR Paris Europe \n7 Germany DE Berlin Europe \n8 Italy IT Rome Europe \n9 Spain ES Madrid Europe \n10 China CN Beijing Asia \n11 Japan JP Tokyo Asia \n12 India IN New Delhi Asia \n13 South Korea KR Seoul Asia \n14 Indonesia ID Jakarta Asia \n15 Australia AU Canberra Oceania \n16 New Zealand NZ Wellington Oceania \n17 Egypt EG Cairo Africa \n18 Nigeria NG Abuja Africa \n19 South Africa ZA Pretoria Africa \n\n languages \n0 [English] \n1 [English, French] \n2 [Spanish] \n3 [Portuguese] \n4 [Spanish] \n5 [English] \n6 [French] \n7 [German] \n8 [Italian] \n9 [Spanish] \n10 [Standard Chinese] \n11 [Japanese] \n12 [Hindi, English] \n13 [Korean] \n14 [Indonesian] \n15 [English] \n16 [English, Māori] \n17 [Arabic] \n18 [English] \n19 [Zulu, Xhosa, Afrikaans, English, Northern Sot... ", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
namecodecapitalcontinentlanguages
0United StatesUSWashington, D.C.North America[English]
1CanadaCAOttawaNorth America[English, French]
2MexicoMXMexico CityNorth America[Spanish]
3BrazilBRBrasíliaSouth America[Portuguese]
4ArgentinaARBuenos AiresSouth America[Spanish]
5United KingdomGBLondonEurope[English]
6FranceFRParisEurope[French]
7GermanyDEBerlinEurope[German]
8ItalyITRomeEurope[Italian]
9SpainESMadridEurope[Spanish]
10ChinaCNBeijingAsia[Standard Chinese]
11JapanJPTokyoAsia[Japanese]
12IndiaINNew DelhiAsia[Hindi, English]
13South KoreaKRSeoulAsia[Korean]
14IndonesiaIDJakartaAsia[Indonesian]
15AustraliaAUCanberraOceania[English]
16New ZealandNZWellingtonOceania[English, Māori]
17EgyptEGCairoAfrica[Arabic]
18NigeriaNGAbujaAfrica[English]
19South AfricaZAPretoriaAfrica[Zulu, Xhosa, Afrikaans, English, Northern Sot...
\n
" }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "pd.DataFrame(objects)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.413360Z", "start_time": "2024-06-23T01:28:18.400360Z" } }, "id": "e98f9d6eb4a5e385" }, { "cell_type": "markdown", "source": [ "## Inserting objects\n", "\n", "We will call `insert` on the collection to add the objects. Note we haven't specified a schema - this will be induced." ], "metadata": { "collapsed": false }, "id": "d4db12be6a95b027" }, { "cell_type": "code", "execution_count": 9, "outputs": [], "source": [ "collection.insert(objects)" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.538479Z", "start_time": "2024-06-23T01:28:18.411461Z" } }, "id": "668e59a8f28e7bfe" }, { "cell_type": "markdown", "source": [ "Let's check this worked by querying:" ], "metadata": { "collapsed": false }, "id": "6a675e8546610e89" }, { "cell_type": "code", "execution_count": 10, "outputs": [], "source": [ "qr = collection.find()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.545205Z", "start_time": "2024-06-23T01:28:18.539041Z" } }, "id": "9575e280dda32e41" }, { "cell_type": "code", "execution_count": 11, "outputs": [ { "data": { "text/plain": " name code capital continent \\\n0 United States US Washington, D.C. North America \n1 Canada CA Ottawa North America \n2 Mexico MX Mexico City North America \n3 Brazil BR Brasília South America \n4 Argentina AR Buenos Aires South America \n5 United Kingdom GB London Europe \n6 France FR Paris Europe \n7 Germany DE Berlin Europe \n8 Italy IT Rome Europe \n9 Spain ES Madrid Europe \n10 China CN Beijing Asia \n11 Japan JP Tokyo Asia \n12 India IN New Delhi Asia \n13 South Korea KR Seoul Asia \n14 Indonesia ID Jakarta Asia \n15 Australia AU Canberra Oceania \n16 New Zealand NZ Wellington Oceania \n17 Egypt EG Cairo Africa \n18 Nigeria NG Abuja Africa \n19 South Africa ZA Pretoria Africa \n\n languages \n0 [English] \n1 [English, French] \n2 [Spanish] \n3 [Portuguese] \n4 [Spanish] \n5 [English] \n6 [French] \n7 [German] \n8 [Italian] \n9 [Spanish] \n10 [Standard Chinese] \n11 [Japanese] \n12 [Hindi, English] \n13 [Korean] \n14 [Indonesian] \n15 [English] \n16 [English, Māori] \n17 [Arabic] \n18 [English] \n19 [Zulu, Xhosa, Afrikaans, English, Northern Sot... ", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
namecodecapitalcontinentlanguages
0United StatesUSWashington, D.C.North America[English]
1CanadaCAOttawaNorth America[English, French]
2MexicoMXMexico CityNorth America[Spanish]
3BrazilBRBrasíliaSouth America[Portuguese]
4ArgentinaARBuenos AiresSouth America[Spanish]
5United KingdomGBLondonEurope[English]
6FranceFRParisEurope[French]
7GermanyDEBerlinEurope[German]
8ItalyITRomeEurope[Italian]
9SpainESMadridEurope[Spanish]
10ChinaCNBeijingAsia[Standard Chinese]
11JapanJPTokyoAsia[Japanese]
12IndiaINNew DelhiAsia[Hindi, English]
13South KoreaKRSeoulAsia[Korean]
14IndonesiaIDJakartaAsia[Indonesian]
15AustraliaAUCanberraOceania[English]
16New ZealandNZWellingtonOceania[English, Māori]
17EgyptEGCairoAfrica[Arabic]
18NigeriaNGAbujaAfrica[English]
19South AfricaZAPretoriaAfrica[Zulu, Xhosa, Afrikaans, English, Northern Sot...
\n
" }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qr.rows_dataframe" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.565655Z", "start_time": "2024-06-23T01:28:18.543251Z" } }, "id": "9b65321ea7c7ee15" }, { "cell_type": "markdown", "source": [ "## Queries\n", "\n", "We can specify key-value constraints:" ], "metadata": { "collapsed": false }, "id": "f49056b209918a9" }, { "cell_type": "code", "execution_count": 12, "outputs": [], "source": [ "qr = collection.find({\"continent\": \"Europe\"})" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.570709Z", "start_time": "2024-06-23T01:28:18.565823Z" } }, "id": "244378540320adcf" }, { "cell_type": "code", "execution_count": 13, "outputs": [ { "data": { "text/plain": " name code capital continent languages\n0 United Kingdom GB London Europe [English]\n1 France FR Paris Europe [French]\n2 Germany DE Berlin Europe [German]\n3 Italy IT Rome Europe [Italian]\n4 Spain ES Madrid Europe [Spanish]", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
namecodecapitalcontinentlanguages
0United KingdomGBLondonEurope[English]
1FranceFRParisEurope[French]
2GermanyDEBerlinEurope[German]
3ItalyITRomeEurope[Italian]
4SpainESMadridEurope[Spanish]
\n
" }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qr.rows_dataframe" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.578140Z", "start_time": "2024-06-23T01:28:18.573699Z" } }, "id": "1ff46aef2d8abba1" }, { "cell_type": "markdown", "source": [ "## Facet counts\n", "\n", "We will now do a query fetching facet counts for all fields.\n", "\n", "Unlike Solr, MongoDB doesn't facet natively but under the hood linkml-store implements the necessary logic" ], "metadata": { "collapsed": false }, "id": "b0badaa4915f91ac" }, { "cell_type": "code", "execution_count": 14, "outputs": [], "source": [ "fc = collection.query_facets()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.650731Z", "start_time": "2024-06-23T01:28:18.581128Z" } }, "id": "df3c2afcdb8153e8" }, { "cell_type": "code", "execution_count": 15, "outputs": [ { "data": { "text/plain": "[('Europe', 5),\n ('Asia', 5),\n ('Africa', 3),\n ('North America', 3),\n ('Oceania', 2),\n ('South America', 2)]" }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fc[\"continent\"]" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:18.658173Z", "start_time": "2024-06-23T01:28:18.607131Z" } }, "id": "61cd37ba4849ed22" }, { "cell_type": "markdown", "source": [ "## Creating an LLM embedding index\n", "\n", "We will now attach an indexer. By default the `llm` indexer uses OpenAI so you will need a key:" ], "metadata": { "collapsed": false }, "id": "a27b08ea540659cd" }, { "cell_type": "code", "execution_count": 16, "outputs": [], "source": [ "collection.attach_indexer(\"llm\")" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:19.217982Z", "start_time": "2024-06-23T01:28:18.611918Z" } }, "id": "674607f18f83360c" }, { "cell_type": "markdown", "source": [ "We can now query using the index. Note that search terms need only be *semantically* related, they don't need to contain the same lexical elements" ], "metadata": { "collapsed": false }, "id": "df0094817a4c7980" }, { "cell_type": "code", "execution_count": 17, "outputs": [ { "data": { "text/plain": " score name code capital continent \\\n0 0.770891 United Kingdom GB London Europe \n1 0.758388 Australia AU Canberra Oceania \n2 0.754203 South Korea KR Seoul Asia \n3 0.750652 New Zealand NZ Wellington Oceania \n4 0.750419 United States US Washington, D.C. North America \n5 0.748973 South Africa ZA Pretoria Africa \n6 0.748322 Canada CA Ottawa North America \n7 0.746444 France FR Paris Europe \n8 0.745408 Germany DE Berlin Europe \n9 0.743449 Spain ES Madrid Europe \n10 0.739726 China CN Beijing Asia \n11 0.739504 Nigeria NG Abuja Africa \n12 0.738601 Egypt EG Cairo Africa \n13 0.735424 Brazil BR Brasília South America \n14 0.735056 Mexico MX Mexico City North America \n15 0.734002 Japan JP Tokyo Asia \n16 0.731288 Argentina AR Buenos Aires South America \n17 0.728014 Indonesia ID Jakarta Asia \n18 0.724164 India IN New Delhi Asia \n19 0.723299 Italy IT Rome Europe \n\n languages \n0 [English] \n1 [English] \n2 [Korean] \n3 [English, Māori] \n4 [English] \n5 [Zulu, Xhosa, Afrikaans, English, Northern Sot... \n6 [English, French] \n7 [French] \n8 [German] \n9 [Spanish] \n10 [Standard Chinese] \n11 [English] \n12 [Arabic] \n13 [Portuguese] \n14 [Spanish] \n15 [Japanese] \n16 [Spanish] \n17 [Indonesian] \n18 [Hindi, English] \n19 [Italian] ", "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
scorenamecodecapitalcontinentlanguages
00.770891United KingdomGBLondonEurope[English]
10.758388AustraliaAUCanberraOceania[English]
20.754203South KoreaKRSeoulAsia[Korean]
30.750652New ZealandNZWellingtonOceania[English, Māori]
40.750419United StatesUSWashington, D.C.North America[English]
50.748973South AfricaZAPretoriaAfrica[Zulu, Xhosa, Afrikaans, English, Northern Sot...
60.748322CanadaCAOttawaNorth America[English, French]
70.746444FranceFRParisEurope[French]
80.745408GermanyDEBerlinEurope[German]
90.743449SpainESMadridEurope[Spanish]
100.739726ChinaCNBeijingAsia[Standard Chinese]
110.739504NigeriaNGAbujaAfrica[English]
120.738601EgyptEGCairoAfrica[Arabic]
130.735424BrazilBRBrasíliaSouth America[Portuguese]
140.735056MexicoMXMexico CityNorth America[Spanish]
150.734002JapanJPTokyoAsia[Japanese]
160.731288ArgentinaARBuenos AiresSouth America[Spanish]
170.728014IndonesiaIDJakartaAsia[Indonesian]
180.724164IndiaINNew DelhiAsia[Hindi, English]
190.723299ItalyITRomeEurope[Italian]
\n
" }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qr = collection.search(\"countries with a King or Queen\")\n", "qr.rows_dataframe" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:19.351748Z", "start_time": "2024-06-23T01:28:19.216122Z" } }, "id": "1ddd4ac75719342d" }, { "cell_type": "markdown", "source": [ "The precise ranking could be debated, but in terms of rough semantic distance the first answer is in the right ballpark, at the time of writing. " ], "metadata": { "collapsed": false }, "id": "6f8802b2424d385f" }, { "cell_type": "code", "execution_count": 18, "outputs": [ { "data": { "text/plain": "20" }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qr.num_rows" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:19.354985Z", "start_time": "2024-06-23T01:28:19.350505Z" } }, "id": "fa1cdc4e62ad19a1" }, { "cell_type": "code", "execution_count": 19, "outputs": [ { "data": { "text/plain": "[(0.7708908770614274,\n {'name': 'United Kingdom',\n 'code': 'GB',\n 'capital': 'London',\n 'continent': 'Europe',\n 'languages': ['English']}),\n (0.7583880255490492,\n {'name': 'Australia',\n 'code': 'AU',\n 'capital': 'Canberra',\n 'continent': 'Oceania',\n 'languages': ['English']}),\n (0.754202745445488,\n {'name': 'South Korea',\n 'code': 'KR',\n 'capital': 'Seoul',\n 'continent': 'Asia',\n 'languages': ['Korean']}),\n (0.7506523769140084,\n {'name': 'New Zealand',\n 'code': 'NZ',\n 'capital': 'Wellington',\n 'continent': 'Oceania',\n 'languages': ['English', 'Māori']}),\n (0.7504190890778679,\n {'name': 'United States',\n 'code': 'US',\n 'capital': 'Washington, D.C.',\n 'continent': 'North America',\n 'languages': ['English']}),\n (0.7489726600700292,\n {'name': 'South Africa',\n 'code': 'ZA',\n 'capital': 'Pretoria',\n 'continent': 'Africa',\n 'languages': ['Zulu',\n 'Xhosa',\n 'Afrikaans',\n 'English',\n 'Northern Sotho',\n 'Tswana',\n 'Southern Sotho',\n 'Tsonga',\n 'Swazi',\n 'Venda',\n 'Southern Ndebele']}),\n (0.7483222334041403,\n {'name': 'Canada',\n 'code': 'CA',\n 'capital': 'Ottawa',\n 'continent': 'North America',\n 'languages': ['English', 'French']}),\n (0.7464438929713734,\n {'name': 'France',\n 'code': 'FR',\n 'capital': 'Paris',\n 'continent': 'Europe',\n 'languages': ['French']}),\n (0.7454078196210195,\n {'name': 'Germany',\n 'code': 'DE',\n 'capital': 'Berlin',\n 'continent': 'Europe',\n 'languages': ['German']}),\n (0.7434487849009042,\n {'name': 'Spain',\n 'code': 'ES',\n 'capital': 'Madrid',\n 'continent': 'Europe',\n 'languages': ['Spanish']}),\n (0.7397262074302214,\n {'name': 'China',\n 'code': 'CN',\n 'capital': 'Beijing',\n 'continent': 'Asia',\n 'languages': ['Standard Chinese']}),\n (0.7395038203235198,\n {'name': 'Nigeria',\n 'code': 'NG',\n 'capital': 'Abuja',\n 'continent': 'Africa',\n 'languages': ['English']}),\n (0.7386007424118528,\n {'name': 'Egypt',\n 'code': 'EG',\n 'capital': 'Cairo',\n 'continent': 'Africa',\n 'languages': ['Arabic']}),\n (0.7354238434740793,\n {'name': 'Brazil',\n 'code': 'BR',\n 'capital': 'Brasília',\n 'continent': 'South America',\n 'languages': ['Portuguese']}),\n (0.7350558425995254,\n {'name': 'Mexico',\n 'code': 'MX',\n 'capital': 'Mexico City',\n 'continent': 'North America',\n 'languages': ['Spanish']}),\n (0.7340019061796953,\n {'name': 'Japan',\n 'code': 'JP',\n 'capital': 'Tokyo',\n 'continent': 'Asia',\n 'languages': ['Japanese']}),\n (0.7312880542513781,\n {'name': 'Argentina',\n 'code': 'AR',\n 'capital': 'Buenos Aires',\n 'continent': 'South America',\n 'languages': ['Spanish']}),\n (0.7280135748889252,\n {'name': 'Indonesia',\n 'code': 'ID',\n 'capital': 'Jakarta',\n 'continent': 'Asia',\n 'languages': ['Indonesian']}),\n (0.7241642577932456,\n {'name': 'India',\n 'code': 'IN',\n 'capital': 'New Delhi',\n 'continent': 'Asia',\n 'languages': ['Hindi', 'English']}),\n (0.7232991877572457,\n {'name': 'Italy',\n 'code': 'IT',\n 'capital': 'Rome',\n 'continent': 'Europe',\n 'languages': ['Italian']})]" }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qr.ranked_rows" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:19.362351Z", "start_time": "2024-06-23T01:28:19.357888Z" } }, "id": "9509d574fd222a72" }, { "cell_type": "code", "execution_count": 19, "outputs": [], "source": [], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-06-23T01:28:19.364582Z", "start_time": "2024-06-23T01:28:19.360366Z" } }, "id": "cdd3d5bb25673310" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }