Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Support Programmatic API #616

Open
Mini256 opened this issue Jan 27, 2025 · 3 comments
Open

Draft: Support Programmatic API #616

Mini256 opened this issue Jan 27, 2025 · 3 comments

Comments

@Mini256
Copy link
Member

Mini256 commented Jan 27, 2025

Goal

  • NOT a API SDK, compared to the HTTP API, the programmatic API can further extend the basic workflow of Autoflow by callbacks / hooks and other methods

API Design

Create New Knowledge Base

from autoflow import Autoflow, IndexMethod

autoflow = Autoflow(db_engine)

kb = autoflow.create_knowledge_base(
  name="TiDB's Docs",
  index_methods=[IndexMethod.VECTOR_SEARCH, IndexMethod.KNOWLEDGE_GRAPH]
)

Add/Import Docuemnts into Knowledge Base

Option 1: Add document directly
kb.add_document(Document(name="Introduction TiDB", content="xxxx"))
Option 2: Import document from files.
with open("path/to/doc.md") as file:
  kb.import_document_from_file(file)
Option 3: Import document from other source
metadata_extractor = CustomMetadataExtractor()
ds = DataSource(
  type="github",
  name="TiDB Docs",
  config={
     "repository_url": "https://github.com/pingcap/docs",
     include=["*.md"]
  },
  metadata_extractor=metadata_extractor
)
kb.import_document_from_data_source(ds)

Retrieve Documents

Knowledge Base Level
result = kb.retrieve_chunks(query="What is TiDB?")
Global Level
result = autoflow.retrieve_chunks(query="What is TiDB?")

Retrieve Knowledge Graph

Knowledge Base Level
knowledge_graph = kb.retrieve_knowledge_graph(
    query="Does TiDB support Vector Search?"
)
Global Level
knowledge_graph = autoflow.retrieve_knowledge_graph(
    query="Does TiDB support Vector Search?"
)

Chat with Knowledge Base

chat_engine = ChatEngine(llm, knowledge_bases=[kb], config={})
chat_engine.chat(user_question="What is TiDB", chat_history=[])
stackvm = StackVM(llm)
stackvm.register_tool(...)
stackvm.register_tool(...)
chat_engine = PlanableChatEngine(stackvm=stackvm)
chat_engine.chat(goal="What is TiDB")
@sykp241095
Copy link
Member

sykp241095 commented Jan 27, 2025

How about using wiki to design the whole APIs? There we can design the API directories and each API usage & parameters.

@Mini256
Copy link
Member Author

Mini256 commented Jan 27, 2025

How about using wiki to design the whole APIs?

I don't think we need a wiki. Wiki is not a suitable tool for discussion and review. In this issue, we will only discuss the overall structure, and the specific API parameters should be discussed in the sub issues and PR.

@c4pt0r
Copy link
Member

c4pt0r commented Feb 7, 2025

Can you add some low-level storage API, like Put(K,V) / Get(K,V) / Query(K)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants