背景
今天开始揭开 Chroma query 的实现内幕,如果你之前没有自己看过,读完后,你的内功将得到增强。做到以不变应万变,力求万事成竹于胸。 Chroma query 读完后,你将对 vector db 的 query 逻辑有深刻的认识。世间万物本质大都大同小异,你或许有一种 独上高楼,望尽天涯路 的感觉。话不多说,直接开始分享干货。
直观的代码调用
无论是chroma,还是其他vector db,基本最简单的调用逻辑就是下面几行代码:
# load the document and split it into chunks loader = TextLoader("/RAG1/data/mysql2.txt", encoding='utf-8') documents = loader.load() # split it into chunks text_splitter = CharacterTextSplitter(chunk_size=200, chunk_overlap=0e) docs = text_splitter.split_documents(documents) # create the open-source embedding function embedding_function = OllamaEmbeddings(model='nomic-embed-text') # load it into Chroma db = Chroma.from_documents(docs, embedding_function) # query it query = "SQL中如何批量插入" docs = db.similarity_search_with