mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-11 03:46:52 +08:00
chore: remove tsne unused code (#6077)
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
from sklearn.manifold import TSNE
|
||||
|
||||
from core.rag.datasource.retrieval_service import RetrievalService
|
||||
from core.rag.models.document import Document
|
||||
from core.rag.retrieval.retrival_methods import RetrievalMethod
|
||||
@@ -101,29 +98,6 @@ class HitTestingService:
|
||||
"records": records
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_tsne_positions_from_embeddings(cls, embeddings: list):
|
||||
embedding_length = len(embeddings)
|
||||
if embedding_length <= 1:
|
||||
return [{'x': 0, 'y': 0}]
|
||||
|
||||
noise = np.random.normal(0, 1e-4, np.array(embeddings).shape)
|
||||
concatenate_data = np.array(embeddings) + noise
|
||||
concatenate_data = concatenate_data.reshape(embedding_length, -1)
|
||||
|
||||
perplexity = embedding_length / 2 + 1
|
||||
if perplexity >= embedding_length:
|
||||
perplexity = max(embedding_length - 1, 1)
|
||||
|
||||
tsne = TSNE(n_components=2, perplexity=perplexity, early_exaggeration=12.0)
|
||||
data_tsne = tsne.fit_transform(concatenate_data)
|
||||
|
||||
tsne_position_data = []
|
||||
for i in range(len(data_tsne)):
|
||||
tsne_position_data.append({'x': float(data_tsne[i][0]), 'y': float(data_tsne[i][1])})
|
||||
|
||||
return tsne_position_data
|
||||
|
||||
@classmethod
|
||||
def hit_testing_args_check(cls, args):
|
||||
query = args['query']
|
||||
|
||||
Reference in New Issue
Block a user