mirror of
https://github.com/ZTatman/Nadir.git
synced 2026-11-20 12:03:30 +00:00
19 lines
526 B
Python
19 lines
526 B
Python
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
import chromadb
|
|
|
|
_DB_PATH = str(Path(__file__).parent / "chroma_db")
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def get_diary_collection():
|
|
"""Retrieves diary chromadb collection by either retrieving one that was already created or by creating a new one
|
|
|
|
Returns:
|
|
A chromadb collection with the name "diary"
|
|
"""
|
|
client = chromadb.PersistentClient(_DB_PATH)
|
|
return client.get_or_create_collection(
|
|
name="diary", metadata={"hnsw:space": "cosine"}
|
|
)
|