Created
February 2, 2025 01:56
-
-
Save xeraa/7a1a606cb991cb7a1035447a7d899251 to your computer and use it in GitHub Desktop.
Getting started with semantic_text on AWS Bedrock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET / | |
PUT starwars | |
{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"my_analyzer": { | |
"char_filter": [ | |
"html_strip" | |
], | |
"tokenizer": "standard", | |
"filter": [ | |
"lowercase", | |
"stop", | |
"snowball" | |
] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"properties": { | |
"quote": { | |
"type": "text", | |
"analyzer": "my_analyzer" | |
} | |
} | |
} | |
} | |
GET starwars/_analyze | |
{ | |
"analyzer" : "my_analyzer", | |
"text": "These are <em>not</em> the droids you are looking for." | |
} | |
PUT starwars/_doc/1 | |
{ | |
"quote": "These are <em>not</em> the droids you are looking for.", | |
"speaker": "Obi-Wan Kenobi" | |
} | |
PUT starwars/_doc/2 | |
{ | |
"quote": "<b>No.</b> I am your father.", | |
"speaker": "Darth Vader" | |
} | |
GET starwars/_search | |
{ | |
"query": { | |
"match": { | |
"quote": "Droid" | |
} | |
} | |
} | |
PUT _inference/completion/titan_completion | |
{ | |
"service": "amazonbedrock", | |
"service_settings": { | |
"access_key": "AKI...", | |
"secret_key": "...", | |
"region": "us-west-2", | |
"provider": "amazontitan", | |
"model": "amazon.titan-text-express-v1" | |
} | |
} | |
POST _inference/completion/titan_completion | |
{ | |
"input": "Who said 'these are not the droids you are looking for'?" | |
} | |
PUT _inference/text_embedding/titan_embeddings | |
{ | |
"service": "amazonbedrock", | |
"service_settings": { | |
"access_key": "AKI...", | |
"secret_key": "...", | |
"region": "us-west-2", | |
"provider": "amazontitan", | |
"model": "amazon.titan-embed-text-v2:0" | |
} | |
} | |
GET _inference | |
PUT semantic-starwars | |
{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"my_analyzer": { | |
"char_filter": [ | |
"html_strip" | |
], | |
"tokenizer": "standard", | |
"filter": [ | |
"lowercase", | |
"stop", | |
"snowball" | |
] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"properties": { | |
"quote": { | |
"type": "text", | |
"analyzer": "my_analyzer", | |
"copy_to": ["quote_titan"] | |
}, | |
"quote_titan": { | |
"type": "semantic_text", | |
"inference_id": "titan_embeddings" | |
} | |
} | |
} | |
} | |
POST _reindex | |
{ | |
"source": { | |
"index": "starwars" | |
}, | |
"dest": { | |
"index": "semantic-starwars" | |
} | |
} | |
GET semantic-starwars/_doc/1 | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"match": { | |
"quote": "robot" | |
} | |
} | |
} | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"semantic": { | |
"field": "quote_titan", | |
"query": "robot" | |
} | |
}, | |
"_source": "quote" | |
} | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"semantic": { | |
"field": "quote_titan", | |
"query": "dad" | |
} | |
}, | |
"_source": "quote" | |
} | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"bool": { | |
"should": [ | |
{ | |
"semantic": { | |
"field": "quote_titan", | |
"query": "android", | |
"boost": 1, | |
"_name": "elser" | |
} | |
}, | |
{ | |
"match": { | |
"quote": { | |
"query": "android", | |
"boost": 3, | |
"_name": "keyword" | |
} | |
} | |
} | |
] | |
} | |
}, | |
"_source": "quote" | |
} | |
DELETE starwars | |
DELETE semantic-starwars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment