Skip to content

Instantly share code, notes, and snippets.

@l2nguyen
l2nguyen / faiss_custom_information_retrieval.py
Created June 3, 2025 16:40
The custom information retrieval loads the stored FAISS index in the connect method. During search any filters can be applied.
from typing import Any, Dict, Text
import structlog
from langchain.schema.embeddings import Embeddings
from langchain.vectorstores import FAISS
from rasa.core.information_retrieval import (
InformationRetrieval,
InformationRetrievalException,
SearchResultList,
)
@l2nguyen
l2nguyen / faiss_custom_ingestion_script.py
Created June 3, 2025 16:39
The script takes care of loading the data from a folder, embedding the documents, and loading the embedded documents into FAISS. In the end the index is stored to disk.
import json
import argparse
import os
import requests
from typing import List
from pathlib import Path
from langchain.schema import Document
from langchain.schema.embeddings import Embeddings
@l2nguyen
l2nguyen / custom_document_retrieval.py
Created May 14, 2025 13:22
custom document retrieval
from __future__ import annotations
from typing import Any, Dict
import structlog
from addons.custom_information_retrieval.custom_faiss_vector_store import CustomFaissVectorStoreWithMetadata
from rasa.document_retrieval.constants import (
POST_PROCESSING_CONFIG_KEY,
QUERY_REWRITING_CONFIG_KEY,
@l2nguyen
l2nguyen / faiss.py
Created April 23, 2025 08:21
FAISS_store class
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Text
import structlog
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.document_loaders.directory import DirectoryLoader
from langchain_community.document_loaders.text import TextLoader
from langchain_community.vectorstores.faiss import FAISS
from rasa.core.information_retrieval import (
@l2nguyen
l2nguyen / multilanguage-migration.py
Created March 31, 2025 14:18
multi-language-migration-script
import argparse
import copy
import io
import os
import sys
from ruamel.yaml import YAML
from typing import Any, Dict, List, Union, Text
# ANSI color codes for pretty output.
YELLOW = "\033[33m"
@l2nguyen
l2nguyen / calm_events_sample.json
Created February 19, 2025 13:57
CALM conversation events examples
{
"event": "action",
"timestamp": 1738252319.367319,
"metadata": {
"model_id": "cf102bc246c7480caa8f5db33fb51aa7",
"assistant_id": "20240418-073244-narrow-archive"
},
"name": "action_session_start",
"policy": null,
"confidence": 1.0,
from typing import AsyncIterator, Dict
import os
import json
import base64
from rasa.core.channels.voice_stream.audio_bytes import RasaAudioBytes
from rasa.core.channels.voice_stream.tts.tts_engine import TTSEngine
OPENAI_API_KEY = "OPENAI_API_KEY"
SYSTEM_MESSAGE = (
"""You are a helpful, creative, clever, and very friendly, for each user message as text,
@l2nguyen
l2nguyen / hqreject.R
Last active December 30, 2019 21:09
Using survey solutions API to reject
library(dplyr)
library(jsonlite)
library(httr)
ids <- c("439e7ee6814b4f1590e46095c7ac573d","167c47df27eb4719bf02f4cf0dea70c3")
comments <- c("API test reject 1!", "API test reject 2!")
user <- "username"
password <- "password"
# function archive one assignment
@l2nguyen
l2nguyen / append_rosters.R
Created July 3, 2019 18:04
Functions to read all files in a folder, rename some variables and append them all together
folder <- '/Computer/my_data_folder'
# read and rename folder for appending
read_rename <- function(x){
require(dplyr) # for data manipulation
require(stringr) # for string functions
require(readr) # for reading in tab files
df <- read_tsv(x) %>%
# removes digit at the end
@l2nguyen
l2nguyen / convert_all.R
Last active July 4, 2019 23:15
Convert all Stata files in a folder to Excel or tab
label_data <- function(dofile, format='tab'){
load_pkg <- function(x) {
if (!require(x, character.only = TRUE)) {
install.packages(x, repos = 'https://cloud.r-project.org/', dep = TRUE)
}
require(x, character.only = TRUE)
}
load_pkg('haven')