Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #99 from pinecone-io/rename_canopy
Browse files Browse the repository at this point in the history
Rename canopy
  • Loading branch information
miararoy authored Oct 25, 2023
2 parents 114cfc4 + 8087c76 commit 456928e
Show file tree
Hide file tree
Showing 90 changed files with 370 additions and 369 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Install the wheel
run: |
pip install dist/pinecone_resin*.whl
pip install dist/pinecone_canopy*.whl
- name: Create dev requirements file
run: |
Expand Down
122 changes: 61 additions & 61 deletions README.md

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions docs/library.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Resin Library
# Canopy Library

For most common use cases, users can simply deploy the fully-configurable [Resin service](../README.md), which provides a REST API backend for your own RAG-infused Chatbot.
For most common use cases, users can simply deploy the fully-configurable [Canopy service](../README.md), which provides a REST API backend for your own RAG-infused Chatbot.

For advanced users, this page describes how to use `resin` core library directly to implement their own custom applications.
For advanced users, this page describes how to use `canopy` core library directly to implement their own custom applications.

The idea behind Resin library is to provide a framework to build AI applications on top of Pinecone as a long memory storage for you own data. Resin library designed with the following principles in mind:
The idea behind Canopy library is to provide a framework to build AI applications on top of Pinecone as a long memory storage for you own data. Canopy library designed with the following principles in mind:

- **Easy to use**: Resin is designed to be easy to use. It is well packaged and can be installed with a single command.
- **Modularity**: Resin is built as a collection of modules that can be used together or separately. For example, you can use the `chat_engine` module to build a chatbot on top of your data, or you can use the `knowledge_base` module to directly store and search your data.
- **Extensibility**: Resin is designed to be extensible. You can easily add your own components and extend the functionality.
- **Production ready**: Resin designed to be production ready, tested, well documented, maintained and supported.
- **Open source**: Resin is open source and free to use. It built in partnership with the community and for the community.
- **Easy to use**: Canopy is designed to be easy to use. It is well packaged and can be installed with a single command.
- **Modularity**: Canopy is built as a collection of modules that can be used together or separately. For example, you can use the `chat_engine` module to build a chatbot on top of your data, or you can use the `knowledge_base` module to directly store and search your data.
- **Extensibility**: Canopy is designed to be extensible. You can easily add your own components and extend the functionality.
- **Production ready**: Canopy designed to be production ready, tested, well documented, maintained and supported.
- **Open source**: Canopy is open source and free to use. It built in partnership with the community and for the community.


## High level architecture
Expand All @@ -19,27 +19,27 @@ The idea behind Resin library is to provide a framework to build AI applications

## Setup

To setup resin, please follow the instructions [here](../README.md#setup).
To setup canopy, please follow the instructions [here](../README.md#setup).

## Quickstart

### Step 1: Initialize global Tokenizer

The `Tokenizer` object is used for converting text into tokens, which is the basic data represntation that is used for processing.

Since manny different classes rely on a tokenizer, Resin uses a singleton `Tokenizer` object which needs to be initialized once.
Since manny different classes rely on a tokenizer, Canopy uses a singleton `Tokenizer` object which needs to be initialized once.

Before instantiating any other resin core objects, please initialize the `Tokenizer` singleton:
Before instantiating any other canopy core objects, please initialize the `Tokenizer` singleton:

```python
from resin.tokenizer import Tokenizer
from canopy.tokenizer import Tokenizer
Tokenizer.initialize()
```

Then, each time you want to use the tokenizer, you can simply instantiate a local object:

```python
from resin.tokenizer import Tokenizer
from canopy.tokenizer import Tokenizer

# no need to pass any parameters, the global tokenizer will be used
tokenizer = Tokenizer()
Expand All @@ -58,7 +58,7 @@ The `Tokenizer` singleton is holding an inner `Tokenizer` object that implements

You can create your own customized tokenizer by implementing a new class that derives from `BaseTokenizer`, then passing this class to the `Tokenizer` singleton during initialization. Example:
```python
from resin.tokenizer import Tokenizer, BaseTokenizer
from canopy.tokenizer import Tokenizer, BaseTokenizer

class CustomTokenizer(BaseTokenizer):
# Implement BaseToknizer's abstract methods, like `def tokenize()` etc.
Expand All @@ -70,8 +70,8 @@ Tokenizer.initialize(tokenizer_class=CustomTokenizer)
When you initialize the `Tokenizer` singleton, you can pass init arguments to the underlying Tokenizer class. Any init argument that is expected by the underlying class's constructor, can be passed as `kwarg` directly to `Tokenizer.initalize()`. For example:

```python
from resin.tokenizer import Tokenizer
from resin.tokenizer.openai import OpenAITokenizer
from canopy.tokenizer import Tokenizer
from canopy.tokenizer.openai import OpenAITokenizer
Tokenizer.initialize(tokenizer_class=OpenAITokenizer, model_name="gpt2")
```

Expand All @@ -85,15 +85,15 @@ Knowledge base is an object that is responsible for storing and query your data.
To create a knowledge base, you can use the following command:

```python
from resin.knowledge_base import KnowledgeBase
from canopy.knowledge_base import KnowledgeBase

kb = KnowledgeBase(index_name="my-index")
```

To create a new Pinecone index and connect it to the knowledge base, you can use the `create_resin_index` method:
To create a new Pinecone index and connect it to the knowledge base, you can use the `create_canopy_index` method:

```python
kb.create_resin_index()
kb.create_canopy_index()
```

Then, you will be able to mange the index in Pinecone [console](https://app.pinecone.io/).
Expand All @@ -117,7 +117,7 @@ To learn more about customizing the KnowledgeBase and its inner components, see
To insert data into the knowledge base, you can create a list of documents and use the `upsert` method:

```python
from resin.models.data_models import Document
from canopy.models.data_models import Document
documents = [Document(id="1", text="U2 are an Irish rock band from Dublin, formed in 1976.", source="https://url.com"),
Document(id="2", text="Arctic Monkeys are an English rock band formed in Sheffield in 2002.", source="https://another-url.com", metadata={"my-key": "my-value"})]
kb.upsert(documents)
Expand All @@ -126,7 +126,7 @@ kb.upsert(documents)
Now you can query the knowledge base with the `query` method to find the most similar documents to a given text:

```python
from resin.models.query_models import Query
from canopy.models.query_models import Query
results = kb.query([Query("Arctic Monkeys music genre"),
Query(text="U2 music genre",
top_k=10,
Expand All @@ -146,7 +146,7 @@ The output of the context engine is designed to provide the LLM the most relevan
To create a context engine using a knowledge base, you can use the following command:

```python
from resin.context_engine import ContextEngine
from canopy.context_engine import ContextEngine
context_engine = ContextEngine(kb)
```

Expand Down Expand Up @@ -183,7 +183,7 @@ Given chat history, the chat engine orchestrates its underlying context engine a
To create a chat engine using a context, you can use the following command:

```python
from resin.chat_engine import ChatEngine
from canopy.chat_engine import ChatEngine
chat_engine = ChatEngine(context_engine)
```

Expand All @@ -195,7 +195,7 @@ chat_engine.chat("what is the genre of Arctic Monkeys band?")
```


Resin designed to be production ready and handle any conversation length and context length. Therefore, the chat engine uses internal components to handle long conversations and long contexts.
Canopy designed to be production ready and handle any conversation length and context length. Therefore, the chat engine uses internal components to handle long conversations and long contexts.
By default, long chat history is truncated to the latest messages that fits the token budget. It orchestrates the context engine to retrieve context that fits the token budget and then use the LLM to generate the next response.


Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tool.poetry]
name = "pinecone-resin"
name = "pinecone-canopy"
version = "0.1.0"
description = "Resin is an orchestration engine for intergating LLMs with Pinecone."
description = "Canopy is an orchestration engine for intergating LLMs with Pinecone."
authors = ["Relevance Team <relevance@pinecone.io>"]
readme = "README.md"
packages = [{include = "resin", from = "src"},
{include = "resin_cli", from = "src"},]
packages = [{include = "canopy", from = "src"},
{include = "canopy_cli", from = "src"},]


[tool.poetry.dependencies]
Expand Down Expand Up @@ -68,5 +68,4 @@ exclude = ['.venv']
max-line-length = 88

[tool.poetry.scripts]
resin = "resin_cli.cli:cli"
service = "resin_cli.service.app:start"
canopy = "canopy_cli.cli:cli"
2 changes: 1 addition & 1 deletion src/resin/__init__.py → src/canopy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import importlib.metadata

# Taken from https://stackoverflow.com/a/67097076
__version__ = importlib.metadata.version("pinecone-resin")
__version__ = importlib.metadata.version("pinecone-canopy")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
from abc import ABC, abstractmethod
from typing import Iterable, Union, Optional, cast

from resin.chat_engine.models import HistoryPruningMethod
from resin.chat_engine.prompt_builder import PromptBuilder
from resin.chat_engine.query_generator import (QueryGenerator,
FunctionCallingQueryGenerator, )
from resin.context_engine import ContextEngine
from resin.tokenizer import Tokenizer
from resin.llm import BaseLLM, OpenAILLM
from resin.llm.models import ModelParams, SystemMessage
from resin.models.api_models import (StreamingChatChunk, ChatResponse,
StreamingChatResponse, )
from resin.models.data_models import Context, Messages
from resin.utils.config import ConfigurableMixin
from canopy.chat_engine.models import HistoryPruningMethod
from canopy.chat_engine.prompt_builder import PromptBuilder
from canopy.chat_engine.query_generator import (QueryGenerator,
FunctionCallingQueryGenerator, )
from canopy.context_engine import ContextEngine
from canopy.tokenizer import Tokenizer
from canopy.llm import BaseLLM, OpenAILLM
from canopy.llm.models import ModelParams, SystemMessage
from canopy.models.api_models import (StreamingChatChunk, ChatResponse,
StreamingChatResponse, )
from canopy.models.data_models import Context, Messages
from canopy.utils.config import ConfigurableMixin

CE_DEBUG_INFO = os.getenv("CE_DEBUG_INFO", "FALSE").lower() == "true"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from abc import ABC, abstractmethod
from typing import Tuple

from resin.tokenizer import Tokenizer
from resin.models.data_models import Messages
from canopy.tokenizer import Tokenizer
from canopy.models.data_models import Messages


class HistoryPruner(ABC):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Tuple

from resin.chat_engine.history_pruner.base import HistoryPruner
from resin.models.data_models import Messages
from canopy.chat_engine.history_pruner.base import HistoryPruner
from canopy.models.data_models import Messages


class RaisingHistoryPruner(HistoryPruner):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Tuple

from resin.chat_engine.history_pruner.base import HistoryPruner
from resin.models.data_models import Messages
from canopy.chat_engine.history_pruner.base import HistoryPruner
from canopy.models.data_models import Messages


class RecentHistoryPruner(HistoryPruner):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from abc import ABC, abstractmethod

from resin.chat_engine.exceptions import InvalidRequestError
from resin.chat_engine.history_pruner import (RaisingHistoryPruner,
RecentHistoryPruner, )
from resin.chat_engine.history_pruner.base import HistoryPruner
from resin.chat_engine.models import HistoryPruningMethod
from resin.tokenizer import Tokenizer
from resin.models.data_models import Messages, Role, MessageBase
from canopy.chat_engine.exceptions import InvalidRequestError
from canopy.chat_engine.history_pruner import (RaisingHistoryPruner,
RecentHistoryPruner, )
from canopy.chat_engine.history_pruner.base import HistoryPruner
from canopy.chat_engine.models import HistoryPruningMethod
from canopy.tokenizer import Tokenizer
from canopy.models.data_models import Messages, Role, MessageBase


class BasePromptBuilder(ABC):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from abc import ABC, abstractmethod
from typing import List

from resin.models.data_models import Messages, Query
from resin.utils.config import ConfigurableMixin
from canopy.models.data_models import Messages, Query
from canopy.utils.config import ConfigurableMixin


class QueryGenerator(ABC, ConfigurableMixin):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List, Optional

from resin.chat_engine.models import HistoryPruningMethod
from resin.chat_engine.prompt_builder import PromptBuilder
from resin.chat_engine.query_generator import QueryGenerator
from resin.llm import BaseLLM, OpenAILLM
from resin.llm.models import (Function, FunctionParameters,
FunctionArrayProperty)
from resin.models.data_models import Messages, Query
from canopy.chat_engine.models import HistoryPruningMethod
from canopy.chat_engine.prompt_builder import PromptBuilder
from canopy.chat_engine.query_generator import QueryGenerator
from canopy.llm import BaseLLM, OpenAILLM
from canopy.llm.models import (Function, FunctionParameters,
FunctionArrayProperty)
from canopy.models.data_models import Messages, Query

DEFAULT_SYSTEM_PROMPT = """Your task is to formulate search queries for a search engine, to assist in responding to the user's question.
You should break down complex questions into sub-queries if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import ABC, abstractmethod
from typing import List

from resin.knowledge_base.models import QueryResult
from resin.models.data_models import Context
from resin.utils.config import ConfigurableMixin
from canopy.knowledge_base.models import QueryResult
from canopy.models.data_models import Context
from canopy.utils.config import ConfigurableMixin


class ContextBuilder(ABC, ConfigurableMixin):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from itertools import zip_longest
from typing import List, Tuple

from resin.context_engine.context_builder.base import ContextBuilder
from resin.context_engine.models import ContextQueryResult, ContextSnippet
from resin.knowledge_base.models import QueryResult, DocumentWithScore
from resin.tokenizer import Tokenizer
from resin.models.data_models import Context
from canopy.context_engine.context_builder.base import ContextBuilder
from canopy.context_engine.models import ContextQueryResult, ContextSnippet
from canopy.knowledge_base.models import QueryResult, DocumentWithScore
from canopy.tokenizer import Tokenizer
from canopy.models.data_models import Context


class StuffingContextBuilder(ContextBuilder):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from abc import ABC, abstractmethod
from typing import List, Optional

from resin.context_engine.context_builder import StuffingContextBuilder
from resin.context_engine.context_builder.base import ContextBuilder
from resin.knowledge_base import KnowledgeBase
from resin.knowledge_base.base import BaseKnowledgeBase
from resin.models.data_models import Context, Query
from resin.utils.config import ConfigurableMixin
from canopy.context_engine.context_builder import StuffingContextBuilder
from canopy.context_engine.context_builder.base import ContextBuilder
from canopy.knowledge_base import KnowledgeBase
from canopy.knowledge_base.base import BaseKnowledgeBase
from canopy.models.data_models import Context, Query
from canopy.utils.config import ConfigurableMixin

CE_DEBUG_INFO = os.getenv("CE_DEBUG_INFO", "FALSE").lower() == "true"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from resin.models.data_models import ContextContent
from canopy.models.data_models import ContextContent


class ContextSnippet(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import ABC, abstractmethod
from typing import List, Optional

from resin.knowledge_base.models import QueryResult
from resin.models.data_models import Query, Document
from resin.utils.config import ConfigurableMixin
from canopy.knowledge_base.models import QueryResult
from canopy.models.data_models import Query, Document
from canopy.utils.config import ConfigurableMixin


class BaseKnowledgeBase(ABC, ConfigurableMixin):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from abc import ABC, abstractmethod
from typing import List

from resin.knowledge_base.models import KBDocChunk
from resin.models.data_models import Document
from resin.utils.config import ConfigurableMixin
from canopy.knowledge_base.models import KBDocChunk
from canopy.models.data_models import Document
from canopy.utils.config import ConfigurableMixin


class Chunker(ABC, ConfigurableMixin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from .langchain_text_splitter import Language, RecursiveCharacterTextSplitter
from .recursive_character import RecursiveCharacterChunker
from resin.knowledge_base.models import KBDocChunk
from resin.models.data_models import Document
from canopy.knowledge_base.models import KBDocChunk
from canopy.models.data_models import Document


class MarkdownChunker(RecursiveCharacterChunker):
Expand Down
Loading

0 comments on commit 456928e

Please sign in to comment.