Quintino Fernandes
commited on
Commit
·
2abbbca
1
Parent(s):
a86dbdc
Similarity fix and entity test
Browse files- database/query.py +4 -1
- models/embedding.py +4 -1
database/query.py
CHANGED
|
@@ -22,6 +22,8 @@ class DatabaseService:
|
|
| 22 |
entities: Optional[List[tuple[str,str]]] = None,
|
| 23 |
limit: int = 10
|
| 24 |
) -> List[Dict[str, any]]:
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
with psycopg2.connect(
|
| 27 |
user=self.DB_USER,
|
|
@@ -150,7 +152,8 @@ class DatabaseService:
|
|
| 150 |
}
|
| 151 |
for content, distance, art_date, art_topic,url in articles
|
| 152 |
]
|
| 153 |
-
|
|
|
|
| 154 |
return formatted_results
|
| 155 |
|
| 156 |
except Exception as e:
|
|
|
|
| 22 |
entities: Optional[List[tuple[str,str]]] = None,
|
| 23 |
limit: int = 10
|
| 24 |
) -> List[Dict[str, any]]:
|
| 25 |
+
|
| 26 |
+
print(f"Extracted entities2: {entities}")
|
| 27 |
try:
|
| 28 |
with psycopg2.connect(
|
| 29 |
user=self.DB_USER,
|
|
|
|
| 152 |
}
|
| 153 |
for content, distance, art_date, art_topic,url in articles
|
| 154 |
]
|
| 155 |
+
cursor.close()
|
| 156 |
+
conn.close()
|
| 157 |
return formatted_results
|
| 158 |
|
| 159 |
except Exception as e:
|
models/embedding.py
CHANGED
|
@@ -7,4 +7,7 @@ class EmbeddingModel:
|
|
| 7 |
self.model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")
|
| 8 |
|
| 9 |
def encode(self, text: str):
|
| 10 |
-
return self.model.encode(text, device=self.device)
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
self.model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")
|
| 8 |
|
| 9 |
def encode(self, text: str):
|
| 10 |
+
return self.model.encode(text, device=self.device)
|
| 11 |
+
|
| 12 |
+
#def similarity(self, embeddings1, embeddings2):
|
| 13 |
+
return self.model.similarity(embeddings1, embeddings2)
|