Skip to content

Commit

Permalink
docs: update Google Spanner Vector Store documentation (#27124)
Browse files Browse the repository at this point in the history
Thank you for contributing to LangChain!

- [X] **PR title**: "package: description"
- Where "package" is whichever of langchain, community, core, etc. is
being modified. Use "docs: ..." for purely docs changes, "templates:
..." for template changes, "infra: ..." for CI changes.
  - Example: "community: add foobar LLM"


- [x] **PR message**: ***Delete this entire checklist*** and replace
with
    - **Description:** Update Spanner VS integration doc
    - **Issue:** None
    - **Dependencies:** None
    - **Twitter handle:** NA


- [x] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

Co-authored-by: Erick Friis <[email protected]>
  • Loading branch information
averikitsch and efriis authored Oct 4, 2024
1 parent 06ce5d1 commit 7a07196
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions docs/docs/integrations/vectorstores/google_spanner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}
],
"source": [
"%pip install --upgrade --quiet langchain-google-spanner"
"%pip install --upgrade --quiet langchain-google-spanner langchain-google-vertexai"
]
},
{
Expand Down Expand Up @@ -124,7 +124,8 @@
"PROJECT_ID = \"my-project-id\" # @param {type:\"string\"}\n",
"\n",
"# Set the project id\n",
"!gcloud config set project {PROJECT_ID}"
"!gcloud config set project {PROJECT_ID}\n",
"%env GOOGLE_CLOUD_PROJECT={PROJECT_ID}"
]
},
{
Expand Down Expand Up @@ -194,14 +195,16 @@
" instance_id=INSTANCE,\n",
" database_id=DATABASE,\n",
" table_name=TABLE_NAME,\n",
" id_column=\"row_id\",\n",
" metadata_columns=[\n",
" TableColumn(name=\"metadata\", type=\"JSON\", is_null=True),\n",
" TableColumn(name=\"title\", type=\"STRING(MAX)\", is_null=False),\n",
" ],\n",
" secondary_indexes=[\n",
" SecondaryIndex(index_name=\"row_id_and_title\", columns=[\"row_id\", \"title\"])\n",
" ],\n",
" # Customize the table creation\n",
" # id_column=\"row_id\",\n",
" # content_column=\"content_column\",\n",
" # metadata_columns=[\n",
" # TableColumn(name=\"metadata\", type=\"JSON\", is_null=True),\n",
" # TableColumn(name=\"title\", type=\"STRING(MAX)\", is_null=False),\n",
" # ],\n",
" # secondary_indexes=[\n",
" # SecondaryIndex(index_name=\"row_id_and_title\", columns=[\"row_id\", \"title\"])\n",
" # ],\n",
")"
]
},
Expand Down Expand Up @@ -262,17 +265,19 @@
" instance_id=INSTANCE,\n",
" database_id=DATABASE,\n",
" table_name=TABLE_NAME,\n",
" ignore_metadata_columns=[],\n",
" embedding_service=embeddings,\n",
" metadata_json_column=\"metadata\",\n",
" # Connect to a custom vector store table\n",
" # id_column=\"row_id\",\n",
" # content_column=\"content\",\n",
" # metadata_columns=[\"metadata\", \"title\"],\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### πŸ” Add Documents\n",
"#### Add Documents\n",
"To add documents in the vector store."
]
},
Expand All @@ -289,14 +294,15 @@
"loader = HNLoader(\"https://news.ycombinator.com/item?id=34817881\")\n",
"\n",
"documents = loader.load()\n",
"ids = [str(uuid.uuid4()) for _ in range(len(documents))]"
"ids = [str(uuid.uuid4()) for _ in range(len(documents))]\n",
"db.add_documents(documents, ids)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### πŸ” Search Documents\n",
"#### Search Documents\n",
"To search documents in the vector store with similarity search."
]
},
Expand All @@ -313,7 +319,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### πŸ” Search Documents\n",
"#### Search Documents\n",
"To search documents in the vector store with max marginal relevance search."
]
},
Expand All @@ -330,7 +336,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### πŸ” Delete Documents\n",
"#### Delete Documents\n",
"To remove documents from the vector store, use the IDs that correspond to the values in the `row_id`` column when initializing the VectorStore."
]
},
Expand All @@ -347,7 +353,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### πŸ” Delete Documents\n",
"#### Delete Documents\n",
"To remove documents from the vector store, you can utilize the documents themselves. The content column and metadata columns provided during VectorStore initialization will be used to find out the rows corresponding to the documents. Any matching rows will then be deleted."
]
},
Expand Down Expand Up @@ -377,7 +383,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 7a07196

Please sign in to comment.