diff --git a/examples/notebooks/experiments.ipynb b/examples/notebooks/experiments.ipynb
index dcdeef3..ebe5289 100644
--- a/examples/notebooks/experiments.ipynb
+++ b/examples/notebooks/experiments.ipynb
@@ -1,9 +1,49 @@
{
"cells": [
+ {
+ "cell_type": "markdown",
+ "id": "8925620d-a388-4e65-948d-2dbb8110da50",
+ "metadata": {},
+ "source": [
+ "# Exploring Sentence, Chunk, and Entity Embeddings for Retrieval \n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f9b62617-ad8b-4a17-92f7-02bf97ac173f",
+ "metadata": {},
+ "source": [
+ "This notebook provides a **proof of concept (PoC)** for working with embeddings in the *Impresso* corpus across three levels of granularity: \n",
+ "\n",
+ "1. **Sentence embeddings** – fine-grained retrieval at the level of individual sentences (e.g., `lepetitparisien-1912-11-13-a-i0001-s-11`). \n",
+ "2. **Chunk embeddings** – broader retrieval at the level of aggregated text chunks (e.g., `lepetitparisien-1912-11-13-a-i0001-c-1`). \n",
+ "3. **Entity embeddings** – retrieval of linked entities (e.g., `Q380083` or `Jonas Furrer`). \n",
+ "\n",
+ "We refer to sentences and chunks as _subdocuments_ and we test these *subdoc* embeddings with two complementary query scenarios: \n",
+ "\n",
+ "- **In-corpus queries** – selecting a query directly from the *Impresso* corpus. \n",
+ "- **Out-of-corpus queries** – embedding an external query (e.g., manually formulated or from another source). \n",
+ "\n",
+ "For the purpose of this PoC:\n",
+ "\n",
+ "👉 The **subdocs** = sentence and chunk embeddings for **front pages** of all newspapers in **1912 (Titanic)** and **1986 (Tchernobyl)**. \n",
+ "👉 The **entities** = entity embeddings for **person entities** in the years [+/- 5y] around the same years.\n",
+ "\n",
+ "From now on, we refer to this PoC as a set of **experiments**. The experiments use direct queries to our internal retrieval system ([Solr](https://solr.apache.org/))."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a8f950b1-132d-4e96-8b24-6d7ef3205f44",
+ "metadata": {},
+ "source": [
+ "Let's first connect to Impresso:"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 1,
- "id": "4298569e",
+ "id": "babd8f0e-b1fd-4000-8bd4-386fbdf83da8",
"metadata": {},
"outputs": [
{
@@ -11,14 +51,14 @@
"output_type": "stream",
"text": [
"🎉 You are now connected to the Impresso API! 🎉\n",
- "🔗 Using API: http://localhost:3030\n"
+ "🔗 Using API: https://dev.impresso-project.ch/public-api/v1\n"
]
}
],
"source": [
"from impresso import connect\n",
"\n",
- "impresso = connect()"
+ "impresso = connect('https://dev.impresso-project.ch/public-api/v1')"
]
},
{
@@ -31,7 +71,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 2,
"id": "509603ee",
"metadata": {},
"outputs": [
@@ -41,7 +81,7 @@
"
\n",
"
\n",
"
FindExperiments result
\n",
- "
Contains 1 items of 1 total items.
\n",
+ "
Contains 2 items of 2 total items.
\n",
"
\n",
"
\n",
"
\n",
@@ -79,15 +119,20 @@
" Experiment with sentence and character level e... | \n",
" \\n Generates embeddings for subdocuments usin... | \n",
" \n",
+ " \n",
+ " | entity-profiles | \n",
+ " Experiment with entity profiles and their embe... | \n",
+ " \\n Generates embeddings for subdocuments usin... | \n",
+ "
\n",
" \n",
"\n",
""
],
"text/plain": [
- ""
+ ""
]
},
- "execution_count": 8,
+ "execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
@@ -101,49 +146,110 @@
"id": "aa567e33",
"metadata": {},
"source": [
- "### Word/Character embeddings experiment"
+ "### Subdoc Embeddings Experiments"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "4969dfde-1089-45c2-bea1-f99c3de2118b",
+ "metadata": {},
+ "source": [
+ "#### Sentence Embeddings - In-corpus queries\n",
+ "\n",
+ "Let's search for some documents, take their embeddings and then search by embedding in Impresso."
]
},
{
"cell_type": "code",
- "execution_count": 32,
- "id": "df2b9dab",
+ "execution_count": 3,
+ "id": "5ef16862-23ad-4447-be29-49be71260333",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
- "Got 1 solr documents\n"
+ "✅ Got 5 Solr document(s)\n",
+ "\n"
]
}
],
"source": [
+ "sentence = \"Le congrès international s'est tenu à Paris pour discuter des avancées scientifiques de la décennie.\"\n",
+ "\n",
"result = impresso.experiments.execute(\n",
- " experiment_id=\"subdoc-embeddings\",\n",
- " body={\n",
- " \"solrPayload\": {\n",
- " \"query\": \"content_txt_fr:chat AND type_s:s\",\n",
- " \"limit\": 1,\n",
- " \"params\": {\n",
- " \"hl\": False\n",
- " }\n",
+ " experiment_id=\"subdoc-embeddings\",\n",
+ " body={\n",
+ " \"solrPayload\": {\n",
+ " \"query\": f\"content_txt_fr:({sentence}) AND type_s:s\", # type_s:s restricts search to sentences\n",
+ " \"limit\": 5,\n",
+ " \"params\": {\"hl\": False}\n",
+ " }\n",
" }\n",
- " }\n",
")\n",
- "print(f\"Got {len(result['solrResponse']['response']['docs'])} solr documents\")"
+ "\n",
+ "docs = result[\"solrResponse\"][\"response\"][\"docs\"]\n",
+ "print(f\"✅ Got {len(docs)} Solr document(s)\\n\")\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "id": "df2b9dab",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "--- Result 1 ---\n",
+ "Mais c’ est une question qui ne peut se régler en congrès internationaux et c’ est pourquoi le pays cjui ne présente pas une natalité suffisante sera étranglé, ce qui ne sera d’ ailleurs qu’ une avance sur son sui- cide.\n",
+ "--- Result 2 ---\n",
+ "ÉDITION DE PARIS Les Eves nouvelles Les suffragettes françaises on * tenu, dimanche, une réunion où fut discutée l' intéressante question du vote municipal des femmes.\n",
+ "--- Result 3 ---\n",
+ "Le 20 juillet 1889, au Congrès socialiste intermfci mal de Paris, il proposa la résolution suivante : « Il sera organisé une grande manifestation internationale à dr.\n",
+ "--- Result 4 ---\n",
+ "Le congrès socialiste de 19 10 a réservé la question de principe, mais il avait stipulé que conformément aux résolutions des congrès internationaux de Paris et d’ Amsterdam, il n’ admettait pas comme possible la participation individuelle de certains socialistes, sans l’ assentiment du parti ouvrier, à un ministère quelconque ; le congrès de 1910 avait décidé, pour le surplus, que la question de la participation gouvernementale est « une question de tactique, et non de principe », qui devra être tranchée par un congrès spécial.\n",
+ "--- Result 5 ---\n",
+ "A l' un des derniers congrès de radiologie, tenu à Bruxelles en septembre 1910.\n"
+ ]
+ }
+ ],
+ "source": [
+ "for i, d in enumerate(docs, 1):\n",
+ " print(f\"--- Result {i} ---\")\n",
+ " print(d.get(\"content_txt_fr\", \"[No text]\"))"
]
},
{
"cell_type": "code",
"execution_count": 26,
- "id": "43a93d9a",
+ "id": "c3dcd90c-0db4-4980-acb5-6f90c2ba7b77",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "'La peau du chat est.'"
+ "['id',\n",
+ " 'imp_ids_ss',\n",
+ " 'surfaces_ss',\n",
+ " 'ci_ids_ss',\n",
+ " 'mention_keys_ss',\n",
+ " 'ci_lg_s',\n",
+ " 'wiki_masterlabel_s',\n",
+ " 'wiki_url_s',\n",
+ " 'date_of_birth_dt',\n",
+ " 'date_of_death_dt',\n",
+ " 'wkd_occupations_ss',\n",
+ " 'wkd_occupation_qids_ss',\n",
+ " 'wkd_entity_types_ss',\n",
+ " 'wiki_summaries_t',\n",
+ " 'contexts_ss',\n",
+ " 'entity_mixed_emb_v768',\n",
+ " 'entity_encyc_emb_v768',\n",
+ " 'entity_media_emb_v768',\n",
+ " '_version_',\n",
+ " '_root_']"
]
},
"execution_count": 26,
@@ -152,13 +258,64 @@
}
],
"source": [
- "doc = result['solrResponse']['response']['docs'][0]\n",
- "doc['content_txt_fr'][:200] # first 200 characters of the document content"
+ "list(docs[0].keys())"
]
},
{
"cell_type": "code",
- "execution_count": 28,
+ "execution_count": 6,
+ "id": "ca0d7ea8-7545-449a-aad3-e95d2ea33fb2",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'Mais c’ est une question qui ne peut se régler en congrès internationaux et c’ est pourquoi le pays cjui ne présente pas une natalité suffisante sera étranglé, ce qui ne sera d’ ailleurs qu’ une avanc'"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "docs[0]['content_txt_fr'][:200] # first 200 characters of the document content"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "54991815-d7d6-4436-82eb-d1948a35aaf8",
+ "metadata": {},
+ "source": [
+ "Let's take the first returned document's embedding."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "id": "0b4d2ef2-bfc1-4941-aba4-ec6ab7002310",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[-0.081427164, 0.064372316, -0.045108054]"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "embedding = docs[0]['gte_multi_v768']\n",
+ "\n",
+ "embedding[:3]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
"id": "f85b2817",
"metadata": {},
"outputs": [],
@@ -168,7 +325,7 @@
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 9,
"id": "b97665a0",
"metadata": {},
"outputs": [
@@ -176,29 +333,45 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Got 3 solr documents\n"
+ "✅ Got 3 Solr document(s)\n",
+ "\n"
]
}
],
"source": [
"result = impresso.experiments.execute(\n",
- " experiment_id=\"subdoc-embeddings\",\n",
- " body={\n",
- " \"solrPayload\": {\n",
- " \"query\": \"{!knn f=gte_multi_v768 topK=3}\" + str(embedding),\n",
- " \"limit\": 3,\n",
- " \"params\": {\n",
- " \"hl\": False\n",
- " }\n",
+ " experiment_id=\"subdoc-embeddings\",\n",
+ " body={\n",
+ " \"solrPayload\": {\n",
+ " \"query\": \"{!knn f=gte_multi_v768 topK=3}\" + str(embedding),\n",
+ " \"limit\": 3,\n",
+ " \"params\": {\n",
+ " \"fq\": \"type_s:s\", # type_s:s restricts search to sentences (s=sentence)\n",
+ " # \"fl\": \"id,score,content_txt_fr,ci_id_s\", -- add these later if you want to return only specific fields\n",
+ " # for now let's return everything\n",
+ " \"hl\": False\n",
+ " }\n",
+ " }\n",
" }\n",
- " }\n",
")\n",
- "print(f\"Got {len(result['solrResponse']['response']['docs'])} solr documents\")"
+ "\n",
+ "docs = result[\"solrResponse\"][\"response\"][\"docs\"]\n",
+ "print(f\"✅ Got {len(docs)} Solr document(s)\\n\")"
]
},
{
"cell_type": "code",
- "execution_count": 34,
+ "execution_count": 10,
+ "id": "09ec22e2-8605-47fe-ae74-10371ffb8453",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# docs"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
"id": "fcc6262c",
"metadata": {},
"outputs": [
@@ -206,42 +379,60 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "A catte occa.\n",
- "C' est.\n",
- "C' est.\n"
+ "--- Result 0 ---\n",
+ "Mais c’ est une question qui ne peut se régler en congrès internationaux et c’ est pourquoi le pays cjui ne présente pas une natalité suffisante sera étranglé, ce qui ne sera d’ ailleurs qu’ une avance sur son sui- cide.\n",
+ "[No text]\n",
+ "--- Result 1 ---\n",
+ "[No text]\n",
+ "weil sie nicht die ganze Nation in dem Parlament vertreten sehen wolle.\n",
+ "--- Result 2 ---\n",
+ "[No text]\n",
+ "Es steht zu hoffen, daß damit die vom Bundesrate getanen völlig gewesen Schritte nicht nutzlos sind, und daß in nicht allzu ferner Zeit doch noch eine solche internationale Konferenz sich mit dein Problem beschäftigen wird.\n"
]
}
],
"source": [
- "for doc in result['solrResponse']['response']['docs']:\n",
- " print(doc['content_txt_fr'][:200]) # first 200 characters of the document content"
+ "for i, d in enumerate(docs):\n",
+ " print(f\"--- Result {i} ---\")\n",
+ " print(d.get(\"content_txt_fr\", \"[No text]\"))\n",
+ " print(d.get(\"content_txt_de\", \"[No text]\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "9822c685-ca20-4277-b4a5-a26290350627",
+ "metadata": {},
+ "source": [
+ "#### Sentence Embeddings - Out-of-corpus queries\n"
]
},
{
"cell_type": "code",
- "execution_count": 44,
+ "execution_count": 12,
"id": "5e6798ed",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
- "'gte-768:ddeJvRe+8TxHOBA9/0EnvbjyubyCSpa9f7kZvfnyzD0/kDo9SV9FvZmMwbyarJc9MMDRvXBQgDySVLy8f9GYPfvy2j1OKVM99wcVPfDZgbyaaJ49WpYmPKOnGLweJCM9zmfHPHZpZT11z0A9FBQ3vWGspL3f3W07ahTyvAufhrxrMVG9zbtivXr+yD26Weq6zegRPYyOv7w6eJ08TdeuPK+2E71tFQ29wS4CvRU/Czt4gYS8Ps4Eu3Y/Xb0l08U9IIdcPGMxFTzxZQQ8n+npvBTgajrIcGI9wZjDPJ2fKzxz9Nu9LI6AvLI+DD25S/m8JJCAPbu5Fbu5gSW9PytTvLBFDb0T/0A80lPOPP6WkryVmOE9O8UuPf2tWL0DxJi8LrcPvS8zpztEn3+8qXSFPYjqpLyn1Ng7NN0bvfS6g7tew+K8jSX8vI0vgjwLGq08rj/fvCgZmL2XPPK8cE0GPcQ5ibzKEFY9YoafPZUQsDvSMz09hokjvM+/azsl/Sq8pwKku/QkkjwIhKS7LXIJvC3dYbwoGX49QX+tPejoxzxgMPY89EwXvSyfQDpojAg5+6O4vQyjOT3klXq8Wy6/vW0XYjv1LGK9L+n8vPTCnbwn9km9UyD7OuVwbjzQqCK9bPRAvFlugDxES1e9guGIvOqur72rQv08oTo9vduE6jwZy908Agf0vAWnjD0uSQq9nx14PJyUuLzkZnE9tq2svGgbLz2EgXQ9kjpjPEs6Bb2VHtu9X9JqO3iElr0UBYU7efgkvCrWUD2GjGW94ilKvLX/FzxIYCc99cRYu01vPjyAmaA8+WszvUa2hjwWNsk8IPSLO2P04TtBupC8l+eIvG0V4z29JF49fFQFvJCgwryb9xq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3Ep/S6ZDcNPOERwzyQOFK91z4FPacj6by5VSG8FWWavHhzozuLHXi8vBl7PcjivTyLEX46ZyszPXFYyDxZqwW8I6o6vWSscb2KCjm82I8TvHHGkTtKaEs8pbAGPczajb2oMwY7jmytvDxx77s/oOe7tHJovRItaryOxPo8n7kkPaxfBj3Pq7E7hl0yvX2MgzxRdrM89UasvBW1pbtT2Co9sG3HuxY7Ej0QcH+83tuKPC6/HrweOfA6aouOvIVCKTzW8Hk9isd6PAE7j7zTPrA95qZbvYaNHr2TUZs8PVvuPO12S70tIwu9GsJWPf3UQT1N6Fe89Q9qvUPpfLsaqlO8r1xbPBQAX7zVRXq9nWmxPEbKWT37ptc8U5c/vAvL+LtCF5o85UzXvIu5UL3a/Tw9BKy9PFy07zz4z487dbTEPNhaBT3kVh49oDU/vMUT7jwseLC8fhhaPYjDjryaaFO7DA0WPFdKgDwvWJC7xXaoPO59nD3bPd47aus1PX0Hr7xLSkC8VMfOO8xbjTxY4+e8qUI6vbafzLp4h+I7o5e/vJoZary7EBu9Edy+PIJmW7we60Y9u7gQO8mIEjx9kI68U0ByPG0WXjyRYJO7st/DPCULnTxz8ha8uPoMvOeHdT1r5KW8GekzPKDXzLy7Bdc7vo8iPToKCDz/+ni9Wdc0PHQYubkXgM461MiGvEauOT3kayA7AsFSvGGLnTsVyyy8WotJvSC1m7xcYgk9ibkyPYtmbjwUNoQ80Q3tPJUc1rxMbEq8k0abPXBMgLyeXyu98+qvPMBW/jzV/Fq8ax3AvNz//zyo2KO8XTsxPd3CNr2uj3c9'"
]
},
- "execution_count": 44,
+ "execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "embedding = impresso.tools.embed_text(text=\"Je suis une théière!\", target=\"text\")\n",
+ "sentence = \"Le congrès international s'est tenu à Paris pour discuter des avancées scientifiques de la décennie.\"\n",
+ "\n",
+ "embedding = impresso.tools.embed_text(text=sentence, target=\"text\")\n",
"embedding"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"id": "0e58b62c",
"metadata": {},
"outputs": [
@@ -251,7 +442,7 @@
"768"
]
},
- "execution_count": 45,
+ "execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
@@ -264,12 +455,38 @@
"_, arr = embedding.split(':')\n",
"arr = base64.b64decode(arr)\n",
"outof_corpus_emb = [struct.unpack('f', arr[i:i+4])[0] for i in range(0, len(arr), 4)]\n",
+ "\n",
"len(outof_corpus_emb)"
]
},
{
"cell_type": "code",
- "execution_count": 46,
+ "execution_count": 14,
+ "id": "09489886-3fd4-498e-b534-298dda3ce96c",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[0.012716123834252357,\n",
+ " 0.0367739275097847,\n",
+ " -0.037758711725473404,\n",
+ " 0.002986321458593011,\n",
+ " -0.08889304101467133]"
+ ]
+ },
+ "execution_count": 14,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "outof_corpus_emb[:5]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
"id": "27b47638",
"metadata": {},
"outputs": [
@@ -277,7 +494,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Got 3 solr documents\n"
+ "✅ Got 3 Solr document(s)\n",
+ "\n"
]
}
],
@@ -294,12 +512,13 @@
" }\n",
" }\n",
")\n",
- "print(f\"Got {len(result['solrResponse']['response']['docs'])} solr documents\")"
+ "docs = result[\"solrResponse\"][\"response\"][\"docs\"]\n",
+ "print(f\"✅ Got {len(docs)} Solr document(s)\\n\")"
]
},
{
"cell_type": "code",
- "execution_count": 47,
+ "execution_count": 16,
"id": "4194268d",
"metadata": {},
"outputs": [
@@ -307,15 +526,193 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "\n",
- "Taïaut !\n",
- "toi !\n"
+ "--- Result 0 ---\n",
+ "[No text]\n",
+ "Bei der internationalen Delegierten konferenz der Notare han.\n",
+ "--- Result 1 ---\n",
+ "[No text]\n",
+ "l \" \" \" erwähnten Kongreß « « « gesetzte internatio. \" \"\n",
+ "--- Result 2 ---\n",
+ "Paris, 10 janvier.\n",
+ "[No text]\n"
+ ]
+ }
+ ],
+ "source": [
+ "for i, d in enumerate(docs):\n",
+ " print(f\"--- Result {i} ---\")\n",
+ " print(d.get(\"content_txt_fr\", \"[No text]\"))\n",
+ " print(d.get(\"content_txt_de\", \"[No text]\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a37c1ea1-6427-40a0-a3e2-101f0804481b",
+ "metadata": {},
+ "source": [
+ "#### Chunk Embeddings - In-corpus queries\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "id": "2eb1d5ad-b9e6-42f0-9a07-8e38f9c9c2c6",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "✅ Got 5 Solr document(s)\n",
+ "\n"
+ ]
+ }
+ ],
+ "source": [
+ "chunk = (\n",
+ " \"Le congrès international s'est tenu à Paris pour discuter des avancées scientifiques de la décennie. \"\n",
+ " \"Des chercheurs venus de nombreux pays ont présenté leurs travaux les plus récents dans les domaines de la physique, \"\n",
+ " \"de la biologie et des sciences sociales. \"\n",
+ " \"Les débats ont mis en lumière les progrès réalisés grâce à la collaboration entre institutions européennes et américaines, \"\n",
+ " \"ainsi que les défis à venir pour une recherche plus ouverte et interdisciplinaire. \"\n",
+ " \"La rencontre s’est conclue par l’adoption d’une résolution encourageant la diffusion libre des connaissances scientifiques.\")\n",
+ "\n",
+ "result = impresso.experiments.execute(\n",
+ " experiment_id=\"subdoc-embeddings\",\n",
+ " body={\n",
+ " \"solrPayload\": {\n",
+ " \"query\": f\"content_txt_fr:({chunk}) AND type_s:c\",\n",
+ " \"limit\": 5,\n",
+ " \"params\": {\"hl\": False}\n",
+ " }\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "docs = result[\"solrResponse\"][\"response\"][\"docs\"]\n",
+ "print(f\"✅ Got {len(docs)} Solr document(s)\\n\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "id": "9d949cbb-3422-435a-8e7e-1816a0ae76b9",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "--- Result 0 ---\n",
+ "et leurs gouvernements respectifs. '.. \".'•••En outre, la nouvelle convention accorde la franchise de port pour la correspondance drdniaire des institutions nationales ayant un caractère scientifique et d' intérêt général ; ainsi qu' aux congrès scientifiques sud-américains composés de la majorité des pays de ce continent.Cette sage disposition constitue pour les sciences un bel encouragement et elle contribuera à répandre avec plus de facilité sur les immenses territoires de l' Amérique du Sud les progrès dus aux- efforts du génie humain.D' autre pari, le congrès postal dont nous analysons les travaux n' a pas blié les services rendus jpar la presse dans le domaine de l' éducation - des peuples.Il a cru devoir également favoriser la diffusion des idées, dans le louable désir d' accélérer - l' avènement de la turité - politique des citoyens.C' est pourquoi la franchise de.port est accordée aux éditeurs de journaux quotidiens et de publications périodiques sud-américains pour les exemplaires jusqu' au nombre de deux échangés par.ces éditeurs entre eux., '.Les Américains, qu' ils soient de souche latine ou anglo-saxonne, ont décidément une manière charmante et bien à eux d' apprêter toutes choses.C.-.\n",
+ "[No text]\n",
+ "--- Result 1 ---\n",
+ "Ces deux domaines nécessitent plus que jamais une collaboration au niveau international.Le séjour de jeunes scientifiques et artistes dans d' autres pays industrialisés d' Europe et d' outre-mer permet un transfert et un échange féconds des connaissances.Aucun scientifique, aucun artiste ne peut de nos jours, s' il veut œuvrer à l' avant-garde de sa discipline ou de son art, ignorer les impulsions venant de l' étranger.La manière la plus efficace d' apprendre à connaître une culture et un patrimoine étrangers est, comme toujours, de séjourner dans le pays concerné.Les contacts avec d' autres pays ont toujours été très importants pour la Suisse.Bien que de nombreux établissements de formation supérieure de l' ensemble des pays maintenant en général leurs portes ouvertes aux étrangers, des bourses gouvernementales, dans certains pays, représentent la seule possibilité pour des Suisses d' avoir accès à leurs hautes écoles ou académies.\n",
+ "[No text]\n",
+ "--- Result 2 ---\n",
+ "Il a écrit dix mémoires ou livres ins- pirés par ses recherches expérimentales.Enfin, il a fourni dix-huit mémoires de physique, publiés dans la Revue scientifique, sur l' évolution de la matière.De plus, Gustave Le Bon a donné à la Bibliothèque de philosophie scientifique, fondée et dirigée par lui, cinq volumes, sur L' Evolution de la Matière, La Psychologie de VEducation, La Psychologie politique, Les Opinions et les Croyances, et, tout dernièrement.\n",
+ "[No text]\n",
+ "--- Result 3 ---\n",
+ "Elle a été intellectualiste.Or, la philosophie nouvelle débute par un # critique, subtile et puisante, de La nature des vérités scientifiques, et de la valeur de l' intelligence comme faculté de connaître.Selon Bergson, le domaine propre de l' intelligence, et aussi bien de la science, œuvre de l' intelligenoe, ce n' est pas le vivant, c' est le matériel, l' inorganique. «JA > monde de la vie et de l' âme, en ce qu' il a d' essentiel et de profond, relève non plus de la connaissance scientifique mais d' uno connaissance spéciale, qui est proprement la connaissance philosophique ou métaphysique », ou encore l' intuition ( 2 ).IJrrgson mtfirme tloac la priorité sur 1 activité réfléchie d' une activité plus obscure et plus riche, qui consiste dans la faculté de sympathiser avec les choses, et qui est.très proche peut-être de l' amour.Cette indépendance de la science et de la connaissance profonde ou intuitive, l' une se bornant à prendre contact avec les choses, 1 autre visant à les comprendre, est d' une extrême conséquence.Le champ de la science, ce n' est donc plus le vrai mais l' utile : son rôle c' est de renforcer notre action sur la nature extérieure, d' aider à la satisfaction de nos besoins matériels, et non point de nous faire connaître la vérité.Pour un philosophe wmme Blondel, oomme Le Roy, \" comme Henri Poincaré, la science elle-même est quelque chose d' infiniment moins réel, eu somme, que la philosophie ; c' est une sorte de symbolisme, arbitraire en son principe, suivi et lié dans son développement continu, et qui d' ailleurs n a point à se préoccuper d' expliquer le fond des choses, mais seulement, de constituer un système de relations cohérentes, en vue de certaines fins pratiques.Devant elle, la loi se présente comme une traduction commode du monde extérieur et, non plus comme un décret qui, ravissant à l' homme sa liberté l, prétend guider sa conduite.L apologétique moderne reçoit de cette philosophie une forme nouvelle.\n",
+ "[No text]\n",
+ "--- Result 4 ---\n",
+ "L' idé.en est due au citoyen Lavigue, de Bordeaux, secrétaire de la- « Fédération nationale des Syndicats de France ».Le 20 juillet 1889, au Congrès socialiste intermfci mal de Paris, il proposa la résolution suivante : « Il sera organisé une grande manifestation internationale à dr.te fixe, de manière que, dans tous les pays et dans toutes les grandes villes à la fois, le même jour _ convenu, les travailleurs mettent les pouvoirs publics en demeure de réduire légalement à huit heures la jovrnée de travail et d' appliquer les _ atit es résolutions du Congrès international de Paris. »Ce texte fut adopté d' enthousiasme.\n",
+ "[No text]\n"
+ ]
+ }
+ ],
+ "source": [
+ "for i, d in enumerate(docs):\n",
+ " print(f\"--- Result {i} ---\")\n",
+ " print(d.get(\"content_txt_fr\", \"[No text]\"))\n",
+ " print(d.get(\"content_txt_de\", \"[No text]\"))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "id": "2311f073-e4c7-48cc-9ed1-d595c8c73e60",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[-0.039117645, 0.062711135, -0.060027212]"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "embedding = docs[0]['gte_multi_v768']\n",
+ "\n",
+ "embedding[:3]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "id": "18b92de3-53b7-4e59-adca-5abf30d0a777",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "✅ Got 3 Solr document(s)\n",
+ "\n"
]
}
],
"source": [
- "for doc in result['solrResponse']['response']['docs']:\n",
- " print(doc.get('content_txt_fr', '')[:200]) # first 200 characters of the document content"
+ "result = impresso.experiments.execute(\n",
+ " experiment_id=\"subdoc-embeddings\",\n",
+ " body={\n",
+ " \"solrPayload\": {\n",
+ " \"query\": \"{!knn f=gte_multi_v768 topK=3}\" + str(embedding),\n",
+ " \"limit\": 3,\n",
+ " \"params\": {\n",
+ " \"fq\": \"type_s:c\", # type_s:c restricts search to chunks! (c=chunk)\n",
+ " # \"fl\": \"id,score,content_txt_fr,ci_id_s\", -- add these later if you want to return only specific fields\n",
+ " # for now let's return everything\n",
+ " \"hl\": False\n",
+ " }\n",
+ " }\n",
+ " }\n",
+ ")\n",
+ "\n",
+ "docs = result[\"solrResponse\"][\"response\"][\"docs\"]\n",
+ "print(f\"✅ Got {len(docs)} Solr document(s)\\n\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "id": "96684e03-a785-4c6f-bb2d-443db7566995",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "--- Result 0 ---\n",
+ "[No text]\n",
+ "gskosten Briefbeföid «.auf die eigentliche Beförderung zwei Drittel aber auf den den Schalterdienst « nd Bestelldienst fallen.Der große Gedanke macht « Schule : er iibec » schritt die Grenzen des Landes ud n versuchte sich auch auf internationalem Boden.Nebst dem Weltpostverein, der uns im Jahre 1875 das internationale Einheitsporto für Briefe brachte, entstanden eine Anzahl Sonderpost der.eine, die Hauptsächlich den Zweck hatten, d « Inlandsporto der Vertragsstaaten auch auf ihren ieg « nseitiaen Auhenveikehr auszudehnen.Selbst uor dem Meere macht « das Einheitsporlo « ich » Halt.Im Jahre 1898 Antrag führte England auf den seines Abgeordneten Henniker-Heaton im Verkehr mit seinen Kolonien das Penny.Porto ein ; Deutschland folgte diesem Beispiele 1N99. Seit 19N8 19l ) 9 verkehrt Großbritannien unö seit auch Deutschland mit den Vereinigten Staaten von Amerika zum Inlandssahe.Begehren Auch in der Schweiz wurden schon laut, öfters die ähnliche Abkommen mit unsern Nachbarstaaten forderten ; nackig doch hart- wehren sich maßgebenden unsere Verwalfundstellen stets dagegen.Immer wird von ihnen nur darauf hingewiesen, baß die nung Ausdeh.\n",
+ "--- Result 1 ---\n",
+ "[No text]\n",
+ "treffenden Branche.Im allgemeinen kann man sagen, batz bei de « gegenwärtigen Sachlage die Ve » arbeltun « de » südamerikanischen Markte » durch entsprechen » vorgebildete Meisende und Spe » zialagenten der Vermittlung durch allgemein « Exporthäuser bei weitem vorzuziehen ist.Frei » lich ist es bei der kleinen Zahl wirklich zuverlässige, und vertrauenswürdiger Agentuifiimen auf den südamerikanischen Plätzen nicht leicht, einen « « igneten Vertreter zu finden und die Fabriken weiden sich im allgemeinen dazu entschließen müssen, neben einer angemessene n Provision einen festen Bureau zufchiih zu leisten und wohlassortierte Muster giati » zu stellen.In der Papierbranche und den ihr verwandten Geschäftszweigen hat der Gedanke, direkt zu exportleren, gleichfalls gemacht.\n",
+ "--- Result 2 ---\n",
+ "[No text]\n",
+ "Am August 24. hat Präsident Taft die Pauamakaual'Vorlage unterzeichnet und ihr ein Memorandum an den Kongreß beigegeben.In Veröffentlichung gelangten dieser zur Denk » schrift führt Taft aus, die Vorlage sei eine der segensreichsten, die je erlassen worden.Er sehe trotz den gegen sie erhobenen Einwendungen lei » nen Grund, bie unbedingt notwendigen Vorkeh » runge » zu verschieben, damit die Welt ihre Vor » bereitungen für die Eröffnung des Panamakanals treffen lönne, wissend, unter welchen Bedingungen dies geschehen werde.Eingehend be » ' handelt das Memorandum die verschiedenen Einwendungen, am ausführlichsten den eng « wegen der Verletzung t » es lischen Protest Ha y. » P a u n c e f o t e'V e r t r a g e s. Dieser Abschnitt darf deshalb eine besonderes Interesse beanspruchen, weil einiges hier zum erstenmal Mls der Protestnote Englands bekannt wird.Taft kommt zu dem Schluß, dah die Vereinigten Staaten üurch den genannten Vertrag sich nicht des Nechts begeben hätten, ihre Schiffe abgaben » frei zu machen oder die Zölle zurüszugeben.Ar « tikel 3 des Vertrages, um den der Streit sich drehe, sei eine Erklärung der Vereinigten Staa » ten, daß der Kanal neutral bleiben solle und bah die Vereinigten Staaten alle Staaten gleich behandeln wollten, sofern diese die Verträgst « « binnimaen erfüllen.DerArtikel stelle mit andern Worten eine Meistbegünstigungsklausel dar, deren Unterlage nicht die Vorteile seien, die die Vereinigten Staaten eigenen ihren Landeskin » öern gewähren, sondern bie Behandlung, die sie andern Nationen angedeihen liehen.Der eng » tische Einspruch würde zu der absurden Schluß » folgerung leiten, daß die Regierung, die den Kn » nal baut, unterhält und verteidigt, sich um das Recht verkürzt sieht, ihren eigene » Handel nach eigenem Ermessen zu führen, während alle an » dern Nationen in dem Wettbewerb mit Amerika dieses Recht uneingeschränkt besitzen, nämlich das Recht der Iollrü'ckvergütungen.Taft protestiert gegen diese Ansicht, als ob die Vereinigten Staaten auf das Recht, ihren Handel zu regeln, verzichten sollten, ein Recht, auf das wederGroßbritannien noch eine andere den Kanal durch » fahrende Nation verzichtet hätte oder verzichten Wolle.Die hat der Nill wie dem sie beglei » renden Memorandum Tafts sofort einen Kom » mental gewidmet, der an Deutlichkeit nichts zu wünschen übrig Iaht und die Stimmung in Eng « land klar illustriert.DaS Londoner Weltblatt bemerkt zunächst, daß der Wortlaut des Pa » namakanalgesetzes sowie der Denkschrift des Präsidenten vorliege, noch wicht baß aber, wenn die telegraphischen Berichte nur richtig einigermaßen seien, das Gesetz mit dem offenkundigen Hin » des Hay-Pauncefote-Vertrages unvereinbar sei.Der letzte Vorschlag des Präsidenten sei etwas Neues in der Geschichte deS Völker » « Feuilleton.\n"
+ ]
+ }
+ ],
+ "source": [
+ "for i, d in enumerate(docs):\n",
+ " print(f\"--- Result {i} ---\")\n",
+ " print(d.get(\"content_txt_fr\", \"[No text]\"))\n",
+ " print(d.get(\"content_txt_de\", \"[No text]\"))"
]
},
{
@@ -328,7 +725,7 @@
},
{
"cell_type": "code",
- "execution_count": 18,
+ "execution_count": 22,
"id": "686d1e8f",
"metadata": {},
"outputs": [
@@ -357,7 +754,7 @@
" '_root_']"
]
},
- "execution_count": 18,
+ "execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
@@ -367,7 +764,7 @@
" experiment_id=\"entity-profiles\",\n",
" body={\n",
" \"solrPayload\": {\n",
- " \"query\": \"wiki_url_s:*Albert*Einstein*\",\n",
+ " \"query\": \"wiki_url_s:*Simone*de*Beauvoir*\",\n",
" \"limit\": 1,\n",
" \"params\": {\n",
" \"hl\": False\n",
@@ -375,13 +772,48 @@
" }\n",
" }\n",
")\n",
- "einstein_doc = result['solrResponse']['response']['docs'][0]\n",
- "list(einstein_doc.keys())"
+ "entity_doc = result['solrResponse']['response']['docs'][0]\n",
+ "\n",
+ "list(entity_doc.keys())"
]
},
{
"cell_type": "code",
- "execution_count": 25,
+ "execution_count": 23,
+ "id": "28d1b084-853b-4e61-8a65-0d61146eb522",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['political philosopher',\n",
+ " 'journalist',\n",
+ " 'novelist',\n",
+ " 'autobiographer',\n",
+ " 'essayist',\n",
+ " 'political activist',\n",
+ " 'diarist',\n",
+ " 'women letter writer',\n",
+ " 'philosopher',\n",
+ " 'literary critic',\n",
+ " 'writer',\n",
+ " 'author',\n",
+ " 'feminist',\n",
+ " 'philosophy teacher']"
+ ]
+ },
+ "execution_count": 23,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "entity_doc['wkd_occupations_ss']"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
"id": "677ca42e",
"metadata": {},
"outputs": [
@@ -389,9 +821,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "https://de.wikipedia.org/wiki/Carl_Einstein\n",
- "https://de.wikipedia.org/wiki/Hendrik_Antoon_Lorentz\n",
- "https://fr.wikipedia.org/wiki/Hippolyte_Fizeau\n"
+ "https://fr.wikipedia.org/wiki/Hélène_de_Beauvoir\n",
+ "https://fr.wikipedia.org/wiki/Jean_Beauvoir\n",
+ "https://fr.wikipedia.org/wiki/Simone_Chalon\n",
+ "https://fr.wikipedia.org/wiki/Sylvia_Earle\n",
+ "https://fr.wikipedia.org/wiki/Gustave_Simon\n"
]
}
],
@@ -400,11 +834,11 @@
" experiment_id=\"entity-profiles\",\n",
" body={\n",
" \"solrPayload\": {\n",
- " \"query\": \"{!knn f=entity_mixed_emb_v768 topK=3}\"+str(einstein_doc['entity_mixed_emb_v768']),\n",
+ " \"query\": \"{!knn f=entity_mixed_emb_v768 topK=5}\" + str(entity_doc['entity_mixed_emb_v768']),\n",
" \"filter\": [\n",
- " f\"-id:{einstein_doc['id']}\" # exclude target entity itself\n",
+ " f\"-id:{entity_doc['id']}\" # exclude target entity itself\n",
" ],\n",
- " \"limit\": 3,\n",
+ " \"limit\": 5,\n",
" \"params\": {\n",
" \"hl\": False\n",
" }\n",
@@ -419,7 +853,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "impresso-py3.13 (3.13.7)",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -433,7 +867,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.13.7"
+ "version": "3.11.10"
}
},
"nbformat": 4,
diff --git a/impresso/resources/tools.py b/impresso/resources/tools.py
index 4315556..cc09715 100644
--- a/impresso/resources/tools.py
+++ b/impresso/resources/tools.py
@@ -189,11 +189,13 @@ def embed_image(
"""Embed an image into a vector space.
Args:
- image (bytes | Base64Str | str): Image to embed. Can be raw bytes, a base64-encoded string, a URL of an image or a path of a file.
- target (ImpressoImageEmbeddingRequestSearchTargetLiteral): Target collection to embed the image into. Currently, only "image" is supported.
+ image (bytes | Base64Str | str): Image to embed. Can be raw bytes, a base64-encoded string,
+ a URL of an image, or a path to a file.
+ target (ImpressoImageEmbeddingRequestSearchTargetLiteral): Target collection to embed the image into.
+ Currently, only "image" is supported.
Returns:
- Embedding: The text embedding as a base64 string prefixed with model tag.
+ Embedding: The image embedding as a base64 string prefixed with model tag.
"""
image_as_base64: str
if isinstance(image, bytes):