0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルLLM × OpenWebUI × ファイルアップロード・ベクトルDB備忘録

Posted at

ollama調査

目的

ollamaを使用してローカルLLMを構築、使ってみるにあたり、気になることを調査する
個人メモです。

1. LLM使用した際のチャット記録

チャット記録がコンテナ内のどこに保存されるかを調査する。
この記事からollamaコンテナとOpenWebUIコンテナを作成している。
履歴はOpenWebUIコンテナが保持しているので、該当コンテナに入って確認。

通常のchat履歴

/app/backend/data/ollama.dbに保存されていることを確認した。
chatのテーブルに保存されており、sqlite3で確認できる。
chatのテーブルの中身は以下のような形で保存されている。

root@2a39da8d3897:/app/backend# ls
__pycache__  apps  config.py  constants.py  data  dev.sh  main.py  requirements.txt  start.sh  utils
root@2a39da8d3897:/app/backend# ls ./data
cache  ollama.db  uploads  vector_db
root@2a39da8d3897:/app/backend# sqlite3 ./data/ollama.db

sqlite> select chat from chat where timestamp=1754825538;
{"id": "", 
"title": "Learning Computer Science Ideas", 
"models": ["phi4-mini:latest"], 
"options": {}, 
"messages": [{"id": "d8289ab5-40f9-42d7-9ee5-ee167248b840", 
"parentId": null, 
"childrenIds": ["469eab5c-e73f-4e12-b8f6-6d4bc8e8a4b8"], 
"role": "user", 
"content": "give me ideas for my learning in computer science", 
"timestamp": 1754825484}, 
{"parentId": "d8289ab5-40f9-42d7-9ee5-ee167248b840", 
"id": "469eab5c-e73f-4e12-b8f6-6d4bc8e8a4b8", 
"childrenIds": [], 
"role": "assistant", 
"content": "Absolutely! Here are some diverse and enriching topics you can explore within the field of Computer Science:\n\n1. **Programming Languages**: Deepen your knowledge with languages like Python, (省略)  Happy Learning!",
 "model": "phi4-mini:latest", 
 "timestamp": 1754825484, 
 "done": true, 
 "context": null, 
 "info": {"total_duration": 52484726685, "load_duration": 2510329176, 
 "prompt_eval_count": 12, 
 "prompt_eval_duration": 237280606, 
 "eval_count": 646, 
 "eval_duration": 49734610480}}], 
 "history": {"messages": {"d8289ab5-40f9-42d7-9ee5-ee167248b840": {"id": "d8289ab5-40f9-42d7-9ee5-ee167248b840", 
 "parentId": null, 
 "childrenIds": ["469eab5c-e73f-4e12-b8f6-6d4bc8e8a4b8"], 
 "role": "user", 
 "content": "give me ideas for my learning in computer science", 
 "timestamp": 1754825484}, 
 "469eab5c-e73f-4e12-b8f6-6d4bc8e8a4b8": {"parentId": "d8289ab5-40f9-42d7-9ee5-ee167248b840",
 "id": "469eab5c-e73f-4e12-b8f6-6d4bc8e8a4b8", 
 childrenIds": [], 
 "role": "assistant", 
 "content": "Absolutely! Here are some diverse and enriching topics you can explore within the field of Computer Science:\n\n1. **Programming Languages**: Deepen your knowledge with languages like Python, (省略) Happy Learning!", 
 "model": "phi4-mini:latest", 
 "timestamp": 1754825484, 
 "done": true, 
 "context": null, 
 "info": {"total_duration": 52484726685, "load_duration": 2510329176, "prompt_eval_count": 12, "prompt_eval_duration": 237280606, "eval_count": 646, "eval_duration": 49734610480}}}, "currentId": "469eab5c-e73f-4e12-b8f6-6d4bc8e8a4b8"}, "tags": [], "timestamp": 1754825484711}

json形式でモデル名とかユーザの役割が何を聞いているか、LLM側がassistantとして何を回答しているかが見える。
ちなみに日本語だとデコードされた形で見えるので、質問文は英語で聞いてみた。

fileをアップロードして聞いてみた場合

システム側でドキュメントの内容を見るように指示している。(raContentの部分)


sqlite> select * from chat where timestamp=1754832409;
8dd89d3b-3577-4ade-a870-2b8f730b74ec|5608374b-d21e-4715-98e5-76386e72a9af|Summarize Document Content|{"id": "", 
"title": "Summarize Document Content", 
"models": ["phi4-mini:latest"], 
"options": {}, 
"messages": [{"id": "045d0e6b-4aea-4372-88ab-94e19a44bd43", 
"parentId": null, 
"childrenIds": ["71847168-5b89-46dd-beff-1dd9e381e323"], 
"role": "user", 
"content": "summarize the document. please tell me short messages.", 
"files": [{"type": "doc", "name": "Document.pdf", 
"collection_name": "3c28d1fa8f61a36b3a945d35e3bd134d20b0505396584cdedfee8fa4d3b21a8", 
"upload_status": true, "error": ""}], 
"raContent": "Use the following context as your learned knowledge, inside <context></context> XML tags.\n\t<context>\n\t  Last weekend, I visited a small town ...(Document.pdfの中身が続く) \n\n\t</context>\n\t\n\tWhen answer to user:\n\t- If you don't know, just say that you don't know.\n\t- If you don't know when you are not sure, ask for clarification.\n\tAvoid mentioning that you obtained the information from the context.\n\tAnd answer according to the language of the user's question.\n\t\t\t\n\tGiven the context information, answer the query.\n\tQuery: summarize the document. please tell me short messages."(長いので省略)

アップロードしたファイルはどこにいっているのか

embedding_fulltext_search_contentの中身は以下のような形で保存されている。今までアップロードしたドキュメントの内容が保存されている。

root@2a39da8d3897:/app/backend# sqlite3 ./data/vector_db/chroma.sqlite3
SQLite version 3.40.1 2022-12-28 14:03:47
Enter ".help" for usage hints.
sqlite> .tables
collection_metadata                embedding_metadata
collections                        embeddings
databases                          embeddings_queue
embedding_fulltext_search          max_seq_id
embedding_fulltext_search_config   migrations
embedding_fulltext_search_content  segment_metadata
embedding_fulltext_search_data     segments
embedding_fulltext_search_docsize  tenants
embedding_fulltext_search_idx
sqlite> select * from embedding_fulltext_search_content;
1|transformerに触れてみる

極性判定や論理関係予測、類似度、固有表現抽出、要約の例
...

embedding_metadataの中身は以下のような形で保存されている。
どこに保存されているか、どのような情報が保存されているかを確認できる。

sqlite> select * from embedding_metadata;
1|source|/app/backend/data/uploads/1章.md|||
1|chroma:document|transformerに触れてみる

極性判定や論理関係予測、類似度、固有表現抽出、要約の例

...

すでに入れいているdocumentを参照するように指示

/app/bacend/data/uploads/Document.pdfをmetadataとして使用しているように見える

sqlite> select * from embedding_metadata;
1|source|/app/backend/data/uploads/1章.md|||
1|chroma:document|transformerに触れてみる
...
2|source|/app/backend/data/uploads/Document.pdf|||
2|page||0||
...

# documentの内容を参照するように指示したら
sqlite> select * from chat where timestamp=1754835519;
... "metadatas": [[{"page": 0, "source": "/app/backend/data/uploads/Document.pdf"}]], ...
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?