Cinnamon / kotaemon

An open-source RAG-based tool for chatting with your documents.
https://cinnamon.github.io/kotaemon/
Apache License 2.0
17.49k stars 1.35k forks source link

feat: kotaemon as service #432

Closed phv2312 closed 3 weeks ago

phv2312 commented 3 weeks ago

Description

Type of change

Checklist

phv2312 commented 3 weeks ago

How to use:

from kotaemon.deps.container import Container
from ktem.index.file.pipelines import DocumentRetrievalPipeline, IndexDocumentPipeline

"""
1. Indexing
"""
indexing_pipeline: IndexDocumentPipeline = Container.indexings.get("default").get()
print(indexing_pipeline)
stream = indexing_pipeline.stream(
    ["<your_filepath>"],
    reindex=True
)
for response in stream:
    print(response)

"""
2. Retriever
"""
crud = Container.crud
docids = crud.list_docids()

retriever_pipeline: DocumentRetrievalPipeline = Container.retrievers.get("default").get()
print(retriever_pipeline)

responses= retriever_pipeline.run(
    text="What is the main content?",
    doc_ids=docids
)
for response in responses:
    print(response.id_)
    print(response.text)