|
|
from qdrant_client import QdrantClient |
|
|
import streamlit as st |
|
|
|
|
|
from qdrant_client.models import Filter |
|
|
from sentence_transformers import SentenceTransformer |
|
|
|
|
|
|
|
|
class NeuralSearcher: |
|
|
def __init__(self, collection_name): |
|
|
self.collection_name = collection_name |
|
|
|
|
|
self.model = SentenceTransformer("all-MiniLM-L6-v2", device="cpu") |
|
|
|
|
|
|
|
|
self.qdrant_client = QdrantClient( |
|
|
url="https://ed55d75f-bb54-4c09-8907-8d112e6278a1.us-east4-0.gcp.cloud.qdrant.io", |
|
|
api_key=st.secrets["QDRANT_API_KEY"], |
|
|
) |
|
|
|
|
|
def search(self, text: str): |
|
|
|
|
|
vector = self.model.encode(text).tolist() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
search_result = self.qdrant_client.search( |
|
|
collection_name=self.collection_name, |
|
|
query_vector=vector, |
|
|
query_filter=None, |
|
|
limit=3, |
|
|
) |
|
|
|
|
|
|
|
|
payloads = [hit.payload for hit in search_result] |
|
|
return payloads |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|