-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KB] create
@kbn/product-doc-artifact-builder
package (#193847)
## Summary Related #193473 Add initial implementation of the knowledge base artifact builder. This PR only introduces the builder script, it doesn't do anything about automation. --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
67f2b7c
commit 1ab1add
Showing
30 changed files
with
1,007 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
require('../src/setup_node_env'); | ||
require('@kbn/product-doc-artifact-builder').runScript(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
x-pack/packages/ai-infra/product-doc-artifact-builder/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @kbn/product-doc-artifact-builder | ||
|
||
Script to build the knowledge base artifacts |
8 changes: 8 additions & 0 deletions
8
x-pack/packages/ai-infra/product-doc-artifact-builder/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { runScript } from './src/command'; |
12 changes: 12 additions & 0 deletions
12
x-pack/packages/ai-infra/product-doc-artifact-builder/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test/jest_node', | ||
rootDir: '../../../..', | ||
roots: ['<rootDir>/x-pack/packages/ai-infra/product-doc-artifact-builder'], | ||
}; |
6 changes: 6 additions & 0 deletions
6
x-pack/packages/ai-infra/product-doc-artifact-builder/kibana.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/product-doc-artifact-builder", | ||
"owner": "@elastic/appex-ai-infra", | ||
"devOnly": true | ||
} |
6 changes: 6 additions & 0 deletions
6
x-pack/packages/ai-infra/product-doc-artifact-builder/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@kbn/product-doc-artifact-builder", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0" | ||
} |
16 changes: 16 additions & 0 deletions
16
x-pack/packages/ai-infra/product-doc-artifact-builder/src/artifact/artifact_name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const getArtifactName = ({ | ||
productName, | ||
productVersion, | ||
}: { | ||
productName: string; | ||
productVersion: string; | ||
}): string => { | ||
return `kibana-kb-${productName}-${productVersion}.zip`.toLowerCase(); | ||
}; |
26 changes: 26 additions & 0 deletions
26
x-pack/packages/ai-infra/product-doc-artifact-builder/src/artifact/manifest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export interface ArtifactManifest { | ||
formatVersion: string; | ||
productName: string; | ||
productVersion: string; | ||
} | ||
|
||
export const getArtifactManifest = ({ | ||
productName, | ||
stackVersion, | ||
}: { | ||
productName: string; | ||
stackVersion: string; | ||
}): ArtifactManifest => { | ||
return { | ||
formatVersion: '1.0.0', | ||
productName, | ||
productVersion: stackVersion, | ||
}; | ||
}; |
39 changes: 39 additions & 0 deletions
39
x-pack/packages/ai-infra/product-doc-artifact-builder/src/artifact/mappings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types'; | ||
|
||
export const getArtifactMappings = (inferenceEndpoint: string): MappingTypeMapping => { | ||
return { | ||
dynamic: 'strict', | ||
properties: { | ||
content_title: { type: 'text' }, | ||
content_body: { | ||
type: 'semantic_text', | ||
inference_id: inferenceEndpoint, | ||
}, | ||
product_name: { type: 'keyword' }, | ||
root_type: { type: 'keyword' }, | ||
slug: { type: 'keyword' }, | ||
url: { type: 'keyword' }, | ||
version: { type: 'version' }, | ||
ai_subtitle: { | ||
type: 'semantic_text', | ||
inference_id: inferenceEndpoint, | ||
}, | ||
ai_summary: { | ||
type: 'semantic_text', | ||
inference_id: inferenceEndpoint, | ||
}, | ||
ai_questions_answered: { | ||
type: 'semantic_text', | ||
inference_id: inferenceEndpoint, | ||
}, | ||
ai_tags: { type: 'keyword' }, | ||
}, | ||
}; | ||
}; |
11 changes: 11 additions & 0 deletions
11
x-pack/packages/ai-infra/product-doc-artifact-builder/src/artifact/product_name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
/** | ||
* The allowed product names, as found in the source's cluster | ||
*/ | ||
export const sourceProductNames = ['Kibana', 'Elasticsearch', 'Security', 'Observability']; |
161 changes: 161 additions & 0 deletions
161
x-pack/packages/ai-infra/product-doc-artifact-builder/src/build_artifacts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import Path from 'path'; | ||
import { Client } from '@elastic/elasticsearch'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { | ||
// checkConnectivity, | ||
createTargetIndex, | ||
extractDocumentation, | ||
indexDocuments, | ||
installElser, | ||
createChunkFiles, | ||
createArtifact, | ||
cleanupFolders, | ||
deleteIndex, | ||
} from './tasks'; | ||
import type { TaskConfig } from './types'; | ||
|
||
const getSourceClient = (config: TaskConfig) => { | ||
return new Client({ | ||
compression: true, | ||
nodes: [config.sourceClusterUrl], | ||
sniffOnStart: false, | ||
auth: { | ||
username: config.sourceClusterUsername, | ||
password: config.sourceClusterPassword, | ||
}, | ||
}); | ||
}; | ||
|
||
const getEmbeddingClient = (config: TaskConfig) => { | ||
return new Client({ | ||
compression: true, | ||
nodes: [config.embeddingClusterUrl], | ||
auth: { | ||
username: config.embeddingClusterUsername, | ||
password: config.embeddingClusterPassword, | ||
}, | ||
// generating embeddings takes time | ||
requestTimeout: 10 * 60 * 1000, | ||
}); | ||
}; | ||
|
||
export const buildArtifacts = async (config: TaskConfig) => { | ||
const log = new ToolingLog({ | ||
level: 'info', | ||
writeTo: process.stdout, | ||
}); | ||
|
||
log.info( | ||
`Starting building artifacts for version=[${ | ||
config.stackVersion | ||
}] and products=[${config.productNames.join(',')}]` | ||
); | ||
|
||
const sourceClient = getSourceClient(config); | ||
const embeddingClient = getEmbeddingClient(config); | ||
|
||
// log.info('Checking connectivity against clusters'); | ||
// await checkConnectivity({ sourceClient, embeddingClient }); | ||
|
||
await cleanupFolders({ folders: [config.buildFolder] }); | ||
|
||
log.info('Ensuring ELSER is installed on the embedding cluster'); | ||
await installElser({ client: embeddingClient }); | ||
|
||
for (const productName of config.productNames) { | ||
await buildArtifact({ | ||
productName, | ||
stackVersion: config.stackVersion, | ||
buildFolder: config.buildFolder, | ||
targetFolder: config.targetFolder, | ||
sourceClient, | ||
embeddingClient, | ||
log, | ||
}); | ||
} | ||
|
||
await cleanupFolders({ folders: [config.buildFolder] }); | ||
}; | ||
|
||
const buildArtifact = async ({ | ||
productName, | ||
stackVersion, | ||
buildFolder, | ||
targetFolder, | ||
embeddingClient, | ||
sourceClient, | ||
log, | ||
}: { | ||
productName: string; | ||
stackVersion: string; | ||
buildFolder: string; | ||
targetFolder: string; | ||
sourceClient: Client; | ||
embeddingClient: Client; | ||
log: ToolingLog; | ||
}) => { | ||
log.info(`Starting building artifact for product [${productName}] and version [${stackVersion}]`); | ||
|
||
const targetIndex = getTargetIndexName({ productName, stackVersion }); | ||
|
||
const documents = await extractDocumentation({ | ||
client: sourceClient, | ||
index: 'search-docs-1', | ||
log, | ||
productName, | ||
stackVersion, | ||
}); | ||
|
||
await createTargetIndex({ | ||
client: embeddingClient, | ||
indexName: targetIndex, | ||
}); | ||
|
||
await indexDocuments({ | ||
client: embeddingClient, | ||
index: targetIndex, | ||
documents, | ||
log, | ||
}); | ||
|
||
await createChunkFiles({ | ||
index: targetIndex, | ||
client: embeddingClient, | ||
productName, | ||
destFolder: Path.join(buildFolder, productName), | ||
log, | ||
}); | ||
|
||
await createArtifact({ | ||
buildFolder: Path.join(buildFolder, productName), | ||
targetFolder, | ||
productName, | ||
stackVersion, | ||
log, | ||
}); | ||
|
||
await deleteIndex({ | ||
indexName: targetIndex, | ||
client: embeddingClient, | ||
log, | ||
}); | ||
|
||
log.info(`Finished building artifact for product [${productName}] and version [${stackVersion}]`); | ||
}; | ||
|
||
const getTargetIndexName = ({ | ||
productName, | ||
stackVersion, | ||
}: { | ||
productName: string; | ||
stackVersion: string; | ||
}) => { | ||
return `kb-artifact-builder-${productName}-${stackVersion}`.toLowerCase(); | ||
}; |
Oops, something went wrong.