💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Update notebook with embeddings update/delete example
davidmezzettie2215b7fade1
diff --git a/examples/01_Introducing_txtai.ipynb b/examples/01_Introducing_txtai.ipynbindex cafff33f..e9756253 100644--- a/examples/01_Introducing_txtai.ipynb+++ b/examples/01_Introducing_txtai.ipynb@@ -79,7 +79,7 @@"%%capture\n","!pip install git+https://github.com/neuml/txtai"],- "execution_count": null,+ "execution_count": 1,"outputs": []},{@@ -107,7 +107,7 @@"# Create embeddings model, backed by sentence-transformers & transformers\n","embeddings = Embeddings({\"method\": \"transformers\", \"path\": \"sentence-transformers/bert-base-nli-mean-tokens\"})"],- "execution_count": null,+ "execution_count": 2,"outputs": []},{@@ -131,7 +131,7 @@"colab": {"base_uri": "https://localhost:8080/"},- "outputId": "1c58e588-2c7e-4202-a636-9f67e24e69b3"+ "outputId": "d953fd27-a026-4ba3-a494-a5944419425b"},"source": ["data = [\"US tops 5 million confirmed virus cases\",\n",@@ -150,7 +150,7 @@"\n"," print(\"%-20s %s\" % (query, data[uid]))"],- "execution_count": null,+ "execution_count": 3,"outputs": [{"output_type": "stream",@@ -200,7 +200,7 @@"colab": {"base_uri": "https://localhost:8080/"},- "outputId": "ed87f588-2cef-4717-b753-8cd152fa4ee7"+ "outputId": "969d6089-f3f9-4172-b0c5-3245f9c4c30e"},"source": ["# Create an index for the list of text\n",@@ -218,7 +218,7 @@" # Print text\n"," print(\"%-20s %s\" % (query, data[uid]))"],- "execution_count": null,+ "execution_count": 4,"outputs": [{"output_type": "stream",@@ -246,7 +246,7 @@"source": ["# Embeddings load/save\n","\n",- "Embeddings indices can be saved to disk and reloaded. At this time, indices are not incrementally created, the index needs a full rebuild to incorporate new data. But that enhancement is in the backlog."+ "Embeddings indices can be saved to disk and reloaded."]},{@@ -257,7 +257,7 @@"colab": {"base_uri": "https://localhost:8080/"},- "outputId": "07e6ce2c-c88c-4955-d210-ce2585e5a79f"+ "outputId": "b287dc2c-75be-4ed3-e488-7d43b7c41b4e"},"source": ["embeddings.save(\"index\")\n",@@ -268,7 +268,7 @@"uid = embeddings.search(\"climate change\", 1)[0][0]\n","print(data[uid])"],- "execution_count": null,+ "execution_count": 5,"outputs": [{"output_type": "stream",@@ -287,12 +287,12 @@"colab": {"base_uri": "https://localhost:8080/"},- "outputId": "c248984d-e855-4585-bc6b-5451aa892403"+ "outputId": "7ba7cba0-5195-43de-9586-10c60ad538bb"},"source": ["!ls index"],- "execution_count": null,+ "execution_count": 6,"outputs": [{"output_type": "stream",@@ -303,6 +303,60 @@}]},+ {+ "cell_type": "markdown",+ "metadata": {+ "id": "6m7sYUj_AdOL"+ },+ "source": [+ "# Embeddings update/delete\n",+ "\n",+ "Updates and deletes are supported for Embedding indices. The upsert operation will insert new data and update existing data\n",+ "\n",+ "The following section runs a query, then updates a value changing the top result and finally deletes the updated value to revert back to the original query results."+ ]+ },+ {+ "cell_type": "code",+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "2CERR0U2Ac8C",+ "outputId": "c14fe04f-0a4c-40d4-cbde-c4180cd8a5c5"+ },+ "source": [+ "# Run initial query\n",+ "uid = embeddings.search(\"feel good story\", 1)[0][0]\n",+ "print(\"Initial: \", data[uid])\n",+ "\n",+ "# Update data\n",+ "data[0] = \"Feel good story: baby panda born\"\n",+ "embeddings.upsert([(0, data[0], None)])\n",+ "\n",+ "uid = embeddings.search(\"feel good story\", 1)[0][0]\n",+ "print(\"After update: \", data[uid])\n",+ "\n",+ "# Remove record just added from index\n",+ "embeddings.delete([0])\n",+ "\n",+ "# Ensure value matches previous value\n",+ "uid = embeddings.search(\"feel good story\", 1)[0][0]\n",+ "print(\"After delete: \", data[uid])"+ ],+ "execution_count": 7,+ "outputs": [+ {+ "output_type": "stream",+ "text": [+ "Initial: Maine man wins $1M from $25 lottery ticket\n",+ "After update: Feel good story: baby panda born\n",+ "After delete: Maine man wins $1M from $25 lottery ticket\n"+ ],+ "name": "stdout"+ }+ ]+ },{"cell_type": "markdown","metadata": {