Lines Matching refs:this

36         $this->db = new SQLiteDB('aichat', DOKU_PLUGIN . 'aichat/db/');
37 $this->db->getPdo()->sqliteCreateFunction('COSIM', $this->sqliteCosineSimilarityCallback(...), 2);
40 $this->useLanguageClusters = $helper->getConf('preferUIlanguage') >= AIChat::LANG_UI_LIMITED;
42 $this->similarityThreshold = $config['similarityThreshold'] / 100;
48 $record = $this->db->queryRecord('SELECT * FROM embeddings WHERE id = ?', [$chunkID]);
66 $this->db->exec('DELETE FROM embeddings');
68 $this->db->exec('DELETE FROM clusters');
81 $this->db->exec('DELETE FROM embeddings WHERE page = ?', [$page]);
88 $this->db->saveRecord('embeddings', [
102 if (!$this->hasClusters()) {
103 $this->createClusters();
105 $this->setChunkClusters();
107 $this->db->exec('VACUUM');
113 $this->createClusters();
114 $this->setChunkClusters();
120 $result = $this->db->queryAll(
141 $cluster = $this->getCluster($vector, $lang);
142 if ($this->logger) $this->logger->info(
147 $result = $this->db->queryAll(
155 [json_encode($vector, JSON_THROW_ON_ERROR), $cluster, $this->similarityThreshold, $limit]
175 $items = $this->db->queryValue('SELECT COUNT(*) FROM embeddings');
176 $size = $this->db->queryValue(
183 $clusters = $this->db->queryKeyValueList($query);
202 return (float)$this->cosineSimilarity(
233 if ($this->useLanguageClusters) {
234 $result = $this->db->queryAll('SELECT DISTINCT lang FROM embeddings');
237 $this->createLanguageClusters($lang);
240 $this->createLanguageClusters('');
253 $where = 'WHERE lang = ' . $this->db->getPdo()->quote($lang);
258 if ($this->logger) $this->logger->info('Creating new {lang} clusters...', ['lang' => $lang]);
259 $this->db->getPdo()->beginTransaction();
263 $this->db->exec($query);
265 $this->db->exec($query);
269 $result = $this->db->queryAll($query, [self::SAMPLE_SIZE]);
280 $total = $this->db->queryValue($query);
283 if ($this->logger) $this->logger->info('Creating {clusters} clusters', ['clusters' => $clustercount]);
293 if ($this->logger) {
295 $this->logger->info('Iteration {iteration}: [{clusters}]', [
306 $this->db->exec($query, [$lang, json_encode($centroid, JSON_THROW_ON_ERROR)]);
309 $this->db->getPdo()->commit();
310 if ($this->logger) $this->logger->success('Created {clusters} clusters', ['clusters' => count($clusters)]);
312 $this->db->getPdo()->rollBack();
324 if ($this->logger) $this->logger->info('Assigning clusters to chunks...');
326 $handle = $this->db->query($query);
330 $cluster = $this->getCluster($vector, $this->useLanguageClusters ? $record['lang'] : '');
332 $this->db->exec($query, [$cluster, $record['id']]);
333 if ($this->logger) $this->logger->success(
350 $where = 'WHERE lang = ' . $this->db->getPdo()->quote($lang);
361 $result = $this->db->queryRecord($query, [json_encode($vector, JSON_THROW_ON_ERROR)]);
373 return $this->db->queryValue($query) > 0;
386 $handle = $this->db->query($query);