rag¶
A module for interacting with Mirascope RAG.
BaseChunker
¶
Bases: BaseModel
, ABC
Base class for chunkers.
Example:
from mirascope.rag import BaseChunker, Document
class TextChunker(BaseChunker):
chunk_size: int
chunk_overlap: int
def chunk(self, text: str) -> list[Document]:
chunks: list[Document] = []
start: int = 0
while start < len(text):
end: int = min(start + self.chunk_size, len(text))
chunks.append(Document(text=text[start:end], id=str(uuid.uuid4())))
start += self.chunk_size - self.chunk_overlap
return chunks
Source code in mirascope/rag/chunkers/base_chunker.py
chunk(text)
abstractmethod
¶
BaseEmbedder
¶
Bases: BaseModel
, Generic[BaseEmbeddingT]
, ABC
The base class abstract interface for interacting with LLM embeddings.
Source code in mirascope/rag/embedders.py
BaseEmbeddingParams
¶
Bases: BaseModel
The parameters with which to make an embedding.
Source code in mirascope/rag/types.py
kwargs()
¶
Returns all parameters for the embedder as a keyword arguments dictionary.
Source code in mirascope/rag/types.py
BaseEmbeddingResponse
¶
Bases: BaseModel
, Generic[ResponseT]
, ABC
A base abstract interface for LLM embedding responses.
Attributes:
Name | Type | Description |
---|---|---|
response |
ResponseT
|
The original response from whichever model response this wraps. |
Source code in mirascope/rag/types.py
embeddings: Optional[Union[list[list[float]], list[list[int]]]]
abstractmethod
property
¶
Should return the embedding of the response.
If there are multiple choices in a response, this method should select the 0th choice and return it's embedding.
BaseQueryResults
¶
BaseVectorStoreParams
¶
Bases: BaseModel
The parameters with which to make a vectorstore.
Source code in mirascope/rag/types.py
kwargs()
¶
Returns all parameters for the index as a keyword arguments dictionary.
Source code in mirascope/rag/types.py
Document
¶
TextChunker
¶
Bases: BaseChunker
A text chunker that splits a text into chunks of a certain size and overlaps.
Example:
from mirascope.rag import TextChunker
text_chunker = TextChunker(chunk_size=1000, chunk_overlap=200)
chunks = text_chunker.chunk("This is a long text that I want to split into chunks.")
print(chunks)