-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.py
More file actions
42 lines (31 loc) · 1 KB
/
Copy pathsearch.py
File metadata and controls
42 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 1. IMPORTS
import warnings
from dotenv import load_dotenv
load_dotenv()
from transformers import logging as hf_logging
hf_logging.set_verbosity_error()
hf_logging.disable_progress_bar()
warnings.filterwarnings("ignore")
from sentence_transformers import SentenceTransformer
from databricks.vector_search.client import VectorSearchClient
# 2. CONFIG
INDEX_NAME = "dv_projc.live_chat.messages_feelings_index"
ENDPOINT_NAME = "hate-or-love-sv"
# 3. MODELO
model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
# 4. CLIENTE
client = VectorSearchClient(disable_notice=True)
index = client.get_index(ENDPOINT_NAME, INDEX_NAME)
# 5. BUSCA
query = "quero matar todo mundo"
query_embedding = model.encode([query])[0].tolist()
results = index.similarity_search(
query_vector=query_embedding,
columns=["id", "text"],
num_results=3,
disable_notice=True
)
# 6. RESULTADOS
print("\nResultados:")
for r in results.get("result", {}).get("data_array", []):
print(f"ID: {r[0]} | Texto: {r[1]}")