|
1 |
| -# New Project Template |
2 |
| - |
3 |
| -This repository contains a template that can be used to seed a repository for a |
4 |
| -new Google open source project. |
5 |
| - |
6 |
| -See [go/releasing](http://go/releasing) (available externally at |
7 |
| -https://opensource.google/documentation/reference/releasing) for more information about |
8 |
| -releasing a new Google open source project. |
9 |
| - |
10 |
| -This template uses the Apache license, as is Google's default. See the |
11 |
| -documentation for instructions on using alternate license. |
12 |
| - |
13 |
| -## How to use this template |
14 |
| - |
15 |
| -1. Clone it from GitHub. |
16 |
| - * There is no reason to fork it. |
17 |
| -1. Create a new local repository and copy the files from this repo into it. |
18 |
| -1. Modify README.md and docs/contributing.md to represent your project, not the |
19 |
| - template project. |
20 |
| -1. Develop your new project! |
21 |
| - |
22 |
| -``` shell |
23 |
| -git clone https://github.com/google/new-project |
24 |
| -mkdir my-new-thing |
25 |
| -cd my-new-thing |
26 |
| -git init |
27 |
| -cp -r ../new-project/* ../new-project/.github . |
28 |
| -git add * |
29 |
| -git commit -a -m 'Boilerplate for new Google open source project' |
| 1 | +# Spanner for LlamaIndex |
| 2 | + |
| 3 | +[](https://cloud.google.com/products#product-launch-stages) |
| 4 | +[](https://pypi.org/project/llama-index-spanner/) |
| 5 | +[](https://pypi.org/project/llama-index-spanner/) |
| 6 | + |
| 7 | + * [Client Library Documentation](https://cloud.google.com/python/docs/reference/llama-index-spanner/latest) |
| 8 | + * [Product Documentation](https://cloud.google.com/spanner) |
| 9 | + |
| 10 | +## Quick Start |
| 11 | + |
| 12 | +In order to use this library, you first need to go through the following steps: |
| 13 | + |
| 14 | +1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) |
| 15 | +2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project) |
| 16 | +3. [Enable the Google Cloud Spanner API.](https://console.cloud.google.com/flows/enableapi?apiid=spanner.googleapis.com) |
| 17 | +4. [Setup Authentication.](https://googleapis.dev/python/google-api-core/latest/auth.html) |
| 18 | + |
| 19 | +### Installation |
| 20 | + |
| 21 | +Install this library in a [virtualenv](https://virtualenv.pypa.io/en/latest/) using pip. [virtualenv](https://virtualenv.pypa.io/en/latest/) is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions. |
| 22 | + |
| 23 | +With [virtualenv](https://virtualenv.pypa.io/en/latest/), it’s possible to install this library without needing system install permissions, and without clashing with the installed system dependencies. |
| 24 | + |
| 25 | +#### Supported Python Versions |
| 26 | + |
| 27 | +Python \>= 3.9 |
| 28 | + |
| 29 | +#### Mac/Linux |
| 30 | + |
| 31 | +```console |
| 32 | +pip install virtualenv |
| 33 | +virtualenv <your-env> |
| 34 | +source <your-env>/bin/activate |
| 35 | +<your-env>/bin/pip install llama-index-spanner |
| 36 | +``` |
| 37 | + |
| 38 | +#### Windows |
| 39 | + |
| 40 | +```console |
| 41 | +pip install virtualenv |
| 42 | +virtualenv <your-env> |
| 43 | +<your-env>\Scripts\activate |
| 44 | +<your-env>\Scripts\pip.exe install llama-index-spanner |
| 45 | +``` |
| 46 | + |
| 47 | +<!-- ### Spanner Property Graph Store Usage |
| 48 | +
|
| 49 | +Use `SpannerPropertyGraphStore` to store nodes and edges extracted from documents. |
| 50 | +
|
| 51 | +```python |
| 52 | +from llama_index_spanner import SpannerPropertyGraphStore |
| 53 | +
|
| 54 | +graph = SpannerPropertyGraphStore( |
| 55 | + instance_id="my-instance", |
| 56 | + database_id="my-database", |
| 57 | + graph_name="my_graph", |
| 58 | +) |
| 59 | +``` |
| 60 | +
|
| 61 | +See the full [Spanner Graph Store](https://github.com/googleapis/langchain-google-spanner-python/blob/main/docs/graph_store.ipynb) tutorial. |
| 62 | +
|
| 63 | +### Spanner Graph Retrievers Usage |
| 64 | +
|
| 65 | +Use `SpannerGraphTextToGQLRetriever` to translate natural language question to GQL and query SpannerGraphStore. |
| 66 | +
|
| 67 | +```python |
| 68 | +from langchain_google_spanner import SpannerGraphStore, SpannerGraphTextToGQLRetriever |
| 69 | +from langchain_google_vertexai import ChatVertexAI |
| 70 | +
|
| 71 | +graph = SpannerGraphStore( |
| 72 | + instance_id="my-instance", |
| 73 | + database_id="my-database", |
| 74 | + graph_name="my_graph", |
| 75 | +) |
| 76 | +llm = ChatVertexAI() |
| 77 | +retriever = SpannerGraphTextToGQLRetriever.from_params( |
| 78 | + graph_store=graph, |
| 79 | + llm=llm |
| 80 | +) |
| 81 | +retriever.invoke("Where does Elias Thorne's sibling live?") |
30 | 82 | ```
|
31 | 83 |
|
32 |
| -## Source Code Headers |
| 84 | +Use `SpannerGraphVectorContextRetriever` to perform vector search on embeddings that are stored in the nodes in a SpannerGraphStore. If expand\_by\_hops is provided, the nodes and edges at a distance upto the expand\_by\_hops from the nodes found in the vector search will also be returned. |
| 85 | +
|
| 86 | +```python |
| 87 | +from langchain_google_spanner import SpannerGraphStore, SpannerGraphVectorContextRetriever |
| 88 | +from langchain_google_vertexai import ChatVertexAI, VertexAIEmbeddings |
| 89 | +
|
| 90 | +graph = SpannerGraphStore( |
| 91 | + instance_id="my-instance", |
| 92 | + database_id="my-database", |
| 93 | + graph_name="my_graph", |
| 94 | +) |
| 95 | +embedding_service = VertexAIEmbeddings(model_name="text-embedding-004") |
| 96 | +retriever = SpannerGraphVectorContextRetriever.from_params( |
| 97 | + graph_store=graph, |
| 98 | + embedding_service=embedding_service, |
| 99 | + label_expr="Person", |
| 100 | + embeddings_column="embeddings", |
| 101 | + top_k=1, |
| 102 | + expand_by_hops=1, |
| 103 | + ) |
| 104 | +retriever.invoke("Who lives in desert?") |
| 105 | +``` --> |
33 | 106 |
|
34 |
| -Every file containing source code must include copyright and license |
35 |
| -information. This includes any JS/CSS files that you might be serving out to |
36 |
| -browsers. (This is to help well-intentioned people avoid accidental copying that |
37 |
| -doesn't comply with the license.) |
| 107 | +## Contributing |
38 | 108 |
|
39 |
| -Apache header: |
| 109 | +Contributions to this library are always welcome and highly encouraged. |
40 | 110 |
|
41 |
| - Copyright 2024 Google LLC |
| 111 | +See [CONTRIBUTING](CONTRIBUTING.md) for more information how to get started. |
42 | 112 |
|
43 |
| - Licensed under the Apache License, Version 2.0 (the "License"); |
44 |
| - you may not use this file except in compliance with the License. |
45 |
| - You may obtain a copy of the License at |
| 113 | +Please note that this project is released with a Contributor Code of Conduct. By participating in |
| 114 | +this project you agree to abide by its terms. See [Code of Conduct](CODE_OF_CONDUCT.md) for more |
| 115 | +information. |
46 | 116 |
|
47 |
| - https://www.apache.org/licenses/LICENSE-2.0 |
| 117 | +## License |
48 | 118 |
|
49 |
| - Unless required by applicable law or agreed to in writing, software |
50 |
| - distributed under the License is distributed on an "AS IS" BASIS, |
51 |
| - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
52 |
| - See the License for the specific language governing permissions and |
53 |
| - limitations under the License. |
| 119 | +Apache 2.0 - See [LICENSE](LICENSE) for more information. |
0 commit comments