Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/flows/base/create_cachedb_hana_plugin/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def create_schema_via_trex(database_code: str, schema_name: str):
# duckdb_data_folder = Variable.get("duckdb_data_folder")
# duckdb_file_path = str(Path(duckdb_data_folder) / f"{database_code}.db")

trex_dao = DBDao(dialect=SupportedDatabaseDialects.TREX, database_code=database_code)
trex_dao = DBDao(dialect=SupportedDatabaseDialects.TREX, database_code=database_code, cache_id=database_code + "_cache")
trex_dao.execute_sql("CALL pg_clear_cache();")
trex_dao.create_schema(f"{database_code}.{schema_name}")
trex_dao.create_schema(f"{database_code}_cache.{schema_name}")

logger.info(f"Schema '{schema_name}' in database '{database_code}' created.")
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ def create_embeddings_hana(dbdao_hana, database_code, schema_name, chunksize):
select_sql = sqla.text(f'SELECT CONCEPT_ID, CONCEPT_NAME FROM {quoted_schema}.CONCEPT')
count_sql = sqla.text(f'SELECT COUNT(*) FROM {quoted_schema}.CONCEPT')

cache_dao = DBDao(dialect=SupportedDatabaseDialects.TREX, database_code=database_code)
# cache_id for HANA is set: database_code + "_cache", according to HANA attachement in trex, otherwise the Trex conncetion will always rounte to HANA instead of the cache
cache_dao = DBDao(dialect=SupportedDatabaseDialects.TREX, database_code=database_code, cache_id=database_code + "_cache")
cache_dao.execute_sql("LOAD vss")

embedding_table = 'concept_name_embeddings'
embedding_cols = {'concept_id': 'INTEGER', embedding_col_name: 'FLOAT[384]'}
db_schema = f"{database_code}.{schema_name}"
db_schema = f"{database_code}_cache.{schema_name}"

# Make sure the cache schema exists before writing embeddings. Mirrors create_cachedb_hana_plugin
cache_dao.execute_sql("CALL pg_clear_cache();")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class HanaHDBDao {
try {
await client.connect();
await client.query(
`ATTACH IF NOT EXISTS '/usr/src/data/cache/${this.databaseCode}.db' AS "${this.databaseCode}"`,
`ATTACH IF NOT EXISTS '/usr/src/data/cache/${this.databaseCode}_cache.db' AS "${this.databaseCode}_cache"`,
);
} catch (err) {
try {
Expand Down Expand Up @@ -358,7 +358,7 @@ export class HanaHDBDao {
string_split('${embedding}', ',')::FLOAT[384]
) AS embd_score
FROM fts_input f
LEFT JOIN "${this.databaseCode}"."${this.schemaName}".concept_name_embeddings e USING (concept_id)
LEFT JOIN "${this.databaseCode}_cache"."${this.schemaName}".concept_name_embeddings e USING (concept_id)
),
stats AS (
SELECT
Expand Down Expand Up @@ -433,7 +433,7 @@ export class HanaHDBDao {
e.concept_name_embedding,
string_split('${embedding}', ',')::FLOAT[384]
) AS embd_score
FROM "${this.databaseCode}"."${this.schemaName}".concept_name_embeddings e
FROM "${this.databaseCode}_cache"."${this.schemaName}".concept_name_embeddings e
ORDER BY embd_score DESC
LIMIT ${env.HANA_HYBRID_TOPK}
`;
Expand Down
7 changes: 4 additions & 3 deletions services/trex/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ export async function initTrex() {
for (const ds of datasets) {
if (ds.dialect !== "hana") continue;
try {
await ensureCacheAttached(ds.code, {
cacheDir: "/usr/src/data/cache",
await ensureCacheAttached(`${ds.code}_cache`, {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is _cache added for HANA datasets?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if cache_id == database_code trex routes to directly HANA connection, but in search_embedding we need hana cache in duckdb cache. So append _cache makes trex to connect cache instead.

createDbFileIfMissing: true,
exec: hanaExec,
});
logger.log(`Attached HANA cache for '${ds.code}'`);
logger.log(`Attached HANA ${ds.code} as ${ds.code}_cache`);
} catch (e) {
logger.error(`Failed to attach HANA cache for '${ds.code}': ${e}`);
}
Expand All @@ -121,6 +121,7 @@ export async function initTrex() {
logger.error(`Failed to enumerate HANA datasets for cache attach: ${e}`);
}


try {
const dbmInstance = await DatabaseManager.get();
const credentials = await dbmInstance.getCredentialsDecrypted();
Expand Down
Loading