Skip to content

Commit

Permalink
stashing
Browse files Browse the repository at this point in the history
  • Loading branch information
mhughes2k committed Mar 11, 2024
1 parent c1f8f9c commit 36e7bf5
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 2 deletions.
4 changes: 2 additions & 2 deletions search/engine/solrrag/classes/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class document extends \search_solr\document {
'indexed' => true,
'mainquery' => true
),
'solr_vector_1356' => [
'type' => 'knn_vector_1356', // this field def seems to be related to the size of the LLM embedding too :-(
'solr_vector_1536' => [
'type' => 'knn_vector_1536', // this field def seems to be related to the size of the LLM embedding too :-(
'stored' => true,
'indexed' => true
],
Expand Down
36 changes: 36 additions & 0 deletions search/engine/solrrag/classes/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,40 @@ protected function execute_solr_knn_query($filters, $accessinfo, $limit) {
}
return [];
}

/**
* @see \search_solr\engine::get_schema_version()
*
* @param $oldversion
* @param $newversion
* @return bool|\lang_string|string
* @throws \coding_exception
* @throws \moodle_exception
*/
protected function update_schema($oldversion, $newversion) {
// Construct schema.
$schema = new \search_solrrag\schema($this);
$cansetup = $schema->can_setup_server();
if ($cansetup !== true) {
return $cansetup;
}

switch ($newversion) {
// This version just requires a setup call to add new fields.
case 2017091700:
$setup = true;
break;

// If we don't know about the schema version we might not have implemented the
// change correctly, so return.
default:
return get_string('schemaversionunknown', 'search');
}

if ($setup) {
$schema->setup();
}

return true;
}
}
37 changes: 37 additions & 0 deletions search/engine/solrrag/cli/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
define("CLI_SCRIPT", true);
require_once("../../../../config.php");

$search = $search = \core_search\manager::instance(true, true);

$engine = $search->get_engine();

/**
* \core\ai\AIProvider
*/
$provider = core\ai\api::get_provider(1);

$doccontent = file_get_contents($CFG->dirroot . "/search/engine/solrrag/tests/testdoc.txt");
if (file_exists($CFG->dirroot . "/search/engine/solrrag/tests/testdoc_vector.txt")) {
$vector = file_get_contents($CFG->dirroot . "/search/engine/solrrag/tests/testdoc_vector.txt");
} else {
$client = new \core\ai\AIClient($provider);
$vector = $client->embed_query($doccontent);
file_put_contents($CFG->dirroot . "/search/engine/solrrag/tests/testdoc_vector.txt", $vector);
}
$doc = [
'id' => 'testdoc',
'solr_vector_1356' => $vector,
'title' => "this is a test document"
];

$document = new \search_solrrag\document("1", "mod_xaichat", "files");
$document->set('title', 'test document');
$document->set('solr_vector_1536', $vector);
$document->set('content',$doccontent);
$document->set('contextid', context_system::instance()->id);
$document->set('courseid', SITEID);
$document->set('owneruserid', $USER->id);
$document->set('modified', time());
$engine->add_document($document);

14 changes: 14 additions & 0 deletions search/engine/solrrag/tests/fixtures/mock_vector_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace search_solrrag;

use core_mocksearch\search\mock_search_area;

defined ('MOODLE_INTERNAL') || die();

/**
* Provides unit test fixtures for vector search tests.
*/
class mock_vector_search extends mock_search_area {


}
32 changes: 32 additions & 0 deletions search/engine/solrrag/tests/fixtures/testable_engine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace search_solr;

/**
* Search engine for testing purposes.
*
* @package search_solr
* @category phpunit
* @copyright 2016 Eric Merrill {@link http://www.merrilldigital.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;

class testable_enginer extends \search_solrrag\engine {

}
10 changes: 10 additions & 0 deletions search/engine/solrrag/tests/testdoc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Moodle requires a directory to store all of its files (all your site's uploaded files, temporary data, cache, session data etc.). The web server needs to be able to write to this directory. On larger systems consider how much free space you are going to use when allocating this directory.

Due to the default way Moodle caches data you may have serious performance issues if you use relatively slow storage (e.g. NFS) for this directory. Read the Performance recommendations carefully and consider using (e.g.) redis or memcached for Caching.

IMPORTANT: This directory must NOT be accessible directly via the web. This would be a serious security hole. Do not try to place it inside your web root or inside your Moodle program files directory. Moodle will not install. It can go anywhere else convenient.

Here is an example (Unix/Linux) of creating the directory and setting the permissions for anyone on the server to write here. This is only appropriate for Moodle servers that are not shared. Discuss this with your server administrator for better permissions that just allow the web server user to access these files.

# mkdir /path/to/moodledata
# chmod 0777 /path/to/moodledata
1 change: 1 addition & 0 deletions search/engine/solrrag/tests/testdoc_vector.txt

Large diffs are not rendered by default.

Loading

0 comments on commit 36e7bf5

Please sign in to comment.