fairsenseai.analysis.risk_assessment.RiskEmbeddingIndex

class RiskEmbeddingIndex(df_risk, df_ai_rmf, faiss_index_file_risk, faiss_index_file_ai_rmf, embedding_model_name='all-MiniLM-L6-v2')[source]

Bases: object

A class that manages dual FAISS indexes for risk analysis and AI RMF (Risk Management Framework) mapping.

Parameters:
  • df_risk (pd.DataFrame) – DataFrame containing risk information with columns RiskID, RiskCategory, and RiskDescription

  • df_ai_rmf (pd.DataFrame) – DataFrame containing AI RMF information with columns section_name, short_description, about, and suggested_actions

  • faiss_index_file_risk (str, optional) – Path to the FAISS index file for risks, by default “fairsenseai/dataframes_and_indexes/risk_index.faiss”

  • faiss_index_file_ai_rmf (str, optional) – Path to the FAISS index file for AI RMF, by default “fairsenseai/dataframes_and_indexes/ai_rmf_index.faiss”

  • embedding_model_name (str, optional) – Name of the sentence transformer model to use as embedder, by default “all-MiniLM-L6-v2”

Examples

>>> risk_df = pd.DataFrame({
...     'RiskID': [1, 2],
...     'RiskCategory': ['Privacy', 'Security'],
...     'RiskDescription': ['Data breach', 'System vulnerability']
... })
>>> rmf_df = pd.DataFrame({
...     'section_name': ['Data Protection', 'System Security'],
...     'short_description': ['Protect user data', 'Secure systems'],
...     'about': ['Data privacy guidelines', 'Security protocols'],
...     'suggested_actions': ['Encrypt data', 'Regular audits']
... })
>>> index = RiskEmbeddingIndex(risk_df, rmf_df)

Methods

risk_with_ai_rmf

Retrieves similar risks and maps them to relevant AI RMF sections using embedding similarity.

risk_with_ai_rmf(query, k_risk=5, k_rmf=1)[source]

Retrieves similar risks and maps them to relevant AI RMF sections using embedding similarity.

Parameters:
  • query (str) – The input text to find similar risks for

  • k_risk (int, optional) – Number of similar risks to retrieve, by default 5

  • k_rmf (int, optional) – Number of AI RMF matches per risk to retrieve, by default 1

Returns:

DataFrame containing matched risks and their corresponding AI RMF sections with columns: MIT RiskID, RiskCategory, RiskDescription, RMFSectionName, RMFShortDescription, RMFAbout, and RMFSuggestedActions

Return type:

pd.DataFrame

Examples

>>> index = RiskEmbeddingIndex(risk_df, rmf_df)
>>> results = index.risk_with_ai_rmf(
...     "AI system handling personal data",
...     k_risk=2,
...     k_rmf=1
... )
>>> print(results[['RiskID', 'RMFSectionName']].head())
   RiskID    RMFSectionName
0      1    Data Protection
1      2    System Security