Last active
November 22, 2024 21:36
-
-
Save xeraa/deb43055ea8c36ecbfc73853304b52fe to your computer and use it in GitHub Desktop.
Elasticsearch ❤️ Ollama
This file contains 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
ollama run llama3.2:1b | |
curl http://localhost:11434/v1/models --silent | jq | |
curl http://localhost:11434/v1/embeddings --silent --json '{ "model": "llama3.2:1b", "input": ["You Know, for Search"] }' | jq | |
curl -fsSL https://elastic.co/start-local | sh |
This file contains 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 | |
{ | |
"field": "quote", | |
"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." | |
} | |
GET starwars/_search | |
{ | |
"query": { | |
"match": { | |
"quote": "Droid" | |
} | |
} | |
} | |
GET starwars/_search | |
{ | |
"query": { | |
"match": { | |
"quote": "robot" | |
} | |
} | |
} | |
PUT _inference/text_embedding/llama3-2_1b | |
{ | |
"service": "openai", | |
"service_settings": { | |
"model_id": "llama3.2:1b", | |
"url": "http://host.docker.internal:11434/v1/embeddings", | |
"api_key": "ignored" | |
} | |
} | |
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_embedding"] | |
}, | |
"quote_embedding": { | |
"type": "semantic_text", | |
"inference_id": "llama3-2_1b" | |
} | |
} | |
} | |
} | |
POST _inference/text_embedding/llama3-2_1b | |
{ | |
"input": "These are <em>not</em> the droids you are looking for." | |
} | |
PUT semantic-starwars/_doc/1 | |
{ | |
"quote": "These are <em>not</em> the droids you are looking for." | |
} | |
GET semantic-starwars/_doc/1 | |
PUT semantic-starwars/_doc/2 | |
{ | |
"quote": "No. I am your father." | |
} | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"match": { | |
"quote": "robot" | |
} | |
} | |
} | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"semantic": { | |
"field": "quote_embedding", | |
"query": "robot" | |
} | |
}, | |
"_source": [ "quote" ] | |
} | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"bool": { | |
"should": [ | |
{ | |
"semantic": { | |
"field": "quote_embedding", | |
"query": "searching for relatives", | |
"_name": "embedding" | |
} | |
}, | |
{ | |
"match": { | |
"quote": { | |
"query": "searching for relatives", | |
"_name": "text" | |
} | |
} | |
} | |
] | |
} | |
}, | |
"_source": [ "quote" ] | |
} | |
GET semantic-starwars/_search | |
{ | |
"query": { | |
"bool": { | |
"should": [ | |
{ | |
"semantic": { | |
"field": "quote_embedding", | |
"query": "look for relatives", | |
"_name": "embedding" | |
} | |
}, | |
{ | |
"match": { | |
"quote": { | |
"query": "look for relatives", | |
"_name": "text" | |
} | |
} | |
} | |
] | |
} | |
}, | |
"_source": [ "quote" ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment