Skip to content

Instantly share code, notes, and snippets.

@g-fukurowl
g-fukurowl / very_simple_rag.py
Created May 12, 2025 22:34
とても簡単なRAG。一問一答形式でクエリを渡すとLLMがベクターストアから関連情報を検索した上で答える。サブコマンドrunで実行。ベクターストアを更新したい時はサブコマンドupdate-vectorで実行。スクリプトと同階層にmodelsディレクトリを作り、ここにgemma-3-1B-it-QAT-Q4_0.ggufを配置しておく必要があるので注意。
from llama_cpp import Llama
from search import search_faiss
from colorama import Fore, Style, init
from langchain_huggingface import HuggingFaceEmbeddings
from langchain_community.vectorstores import FAISS
from langchain.document_loaders import PyPDFLoader, TextLoader, CSVLoader
from langchain.text_splitter import CharacterTextSplitter
import argparse
import sys
@g-fukurowl
g-fukurowl / setup_custom_local_model_for_opensearch.sh
Last active May 13, 2025 05:48
OpenSearchにローカルカスタムモデル(例: multilingual-e5-large-instruct)を導入するスクリプト。モデルデプロイの完了を待たない造りなので注意。最後にFess用の設定も出力する
opensearch_host=$1
pipeline_name=neural_pipeline
tmp_file=/tmp/output.$$
# AT FIRST, READ https://qiita.com/myu65/items/97a66dc8d06be9d99c74
# THEN, EDIT FOLLOWING VARIABLES FOR YOUR MODEL
model_name=intfloat/multilingual-e5-large-instruct
dimension=1024
space_type=cosinesimil
framework_type=huggingface_transformers
@g-fukurowl
g-fukurowl / Dockerfile
Last active May 13, 2025 05:48
fess-mcp-server をコンテナとして定義した DockerFile (pyproject.toml に fess-mcp-server の依存がまとまっている)
# ベースイメージとしてPython 3.10を使用
FROM python:3.10-slim
# 作業ディレクトリを設定
WORKDIR /app
# 必要なシステムパッケージをインストール
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
@g-fukurowl
g-fukurowl / fess_mcp_server.py
Last active May 13, 2025 05:48
オープンソースの全文検索エンジンFESSで検索を行うMCPサーバの実装。Claude for Desktopで動作確認済み。FESSはローカルに立てた
from typing import Any
import asyncio
import httpx
from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("fess-mcp")
# Constants
FESS_API_BASE = "http://localhost:8080/api/v1"
def hoge():
print "hoge"
def test_hoge(capsys):
hoge()
out, err = capsys.readouterr()
assert out == "hoge\n"