When using the `PineconeIndex`, our `RouteLayer` is stored in two places:
* We keep route layer metadata locally.
* Vectors alongside a backup of our metadata is stored remotely in Pinecone.
By storing some data locally and some remotely we achieve improved persistence and the ability to recover our local state if lost. However, it does come with challenges around keep our local and remote instances synchronized. Fortunately, we have [several synchronization options](https://docs.aurelio.ai/semantic-router/route_layer/sync.html). In this example, we'll see how to use these options to keep our local and remote Pinecone instances synchronized.
%% Cell type:code id: tags:
``` python
fromsemantic_routerimportRoute
# we could use this as a guide for our chatbot to avoid political conversations
politics=Route(
name="politics",
utterances=[
"isn't politics the best thing ever",
"why don't you tell me about your political opinions",
"don't you just love the president",
"don't you just hate the president",
"they're going to destroy this country!",
"they will save the country!",
],
)
# this could be used as an indicator to our chatbot to switch to a more
# conversational prompt
chitchat=Route(
name="chitchat",
utterances=[
"how's the weather today?",
"how are things going?",
"lovely weather today",
"the weather is horrendous",
"let's go to the chippy",
],
)
# we place both of our decisions together into single list
routes=[politics,chitchat]
```
%% Cell type:code id: tags:
``` python
importos
fromgetpassimportgetpass
fromsemantic_router.encodersimportOpenAIEncoder
# get at platform.openai.com
os.environ["OPENAI_API_KEY"]=os.environ.get("OPENAI_API_KEY")orgetpass("Enter OpenAI API key: ")
[33m2024-11-10 22:41:41 WARNING semantic_router.utils.logger Local and remote route layers were not aligned. Remote hash not updated. Use `RouteLayer.get_utterance_diff()` to see details.[0m
%% Cell type:markdown id: tags:
Let's try `rl.is_synced()` again:
%% Cell type:code id: tags:
``` python
rl.is_synced()
```
%% Output
hash_id: sr_hash#
False
%% Cell type:markdown id: tags:
We can use the `get_utterance_diff` method to see exactly _why_ our local and remote are not synced
%% Cell type:code id: tags:
``` python
rl.get_utterance_diff()
```
%% Output
['chitchat: how are things going?', "chitchat: how's the weather today?", "chitchat: let's go to the chippy", 'chitchat: lovely weather today', 'chitchat: the weather is horrendous', "politics: don't you just hate the president", "politics: don't you just love the president", "politics: isn't politics the best thing ever", 'politics: they will save the country!', "politics: they're going to destroy this country!", "politics: why don't you tell me about your political opinions"]
["politics: don't you just hate the president", "politics: don't you just love the president", "politics: isn't politics the best thing ever", 'politics: they will save the country!', "politics: they're going to destroy this country!", "politics: why don't you tell me about your political opinions"]
['+ chitchat: how are things going?',
"+ chitchat: how's the weather today?",
"+ chitchat: let's go to the chippy",
'+ chitchat: lovely weather today',
'+ chitchat: the weather is horrendous',
" politics: don't you just hate the president",
" politics: don't you just love the president",
" politics: isn't politics the best thing ever",
' politics: they will save the country!',
" politics: they're going to destroy this country!",
" politics: why don't you tell me about your political opinions"]