Skip to main content
이 노트북은 Psychic에서 문서를 로드하는 방법을 다룹니다. 자세한 내용은 여기를 참조하세요.

전제 조건

  1. 이 문서의 빠른 시작 섹션을 따라 진행하세요
  2. Psychic 대시보드에 로그인하여 시크릿 키를 받으세요
  3. 프론트엔드 React 라이브러리를 웹 앱에 설치하고 사용자가 연결을 인증하도록 하세요. 연결은 지정한 연결 ID를 사용하여 생성됩니다.

문서 로딩

연결에서 문서를 로드하려면 PsychicLoader 클래스를 사용하세요. 각 연결에는 커넥터 ID(연결된 SaaS 앱에 해당)와 연결 ID(프론트엔드 라이브러리에 전달한 ID)가 있습니다.
# Uncomment this to install psychicapi if you don't already have it installed
!poetry run pip -q install psychicapi langchain-chroma
[notice] A new release of pip is available: 23.0.1 -> 23.1.2
[notice] To update, run: pip install -U pip
from langchain_community.document_loaders import PsychicLoader
from psychicapi import ConnectorId

# Create a document loader for google drive. We can also load from other connectors by setting the connector_id to the appropriate value e.g. ConnectorId.notion.value
# This loader uses our test credentials
google_drive_loader = PsychicLoader(
    api_key="7ddb61c1-8b6a-4d31-a58e-30d1c9ea480e",
    connector_id=ConnectorId.gdrive.value,
    connection_id="google-test",
)

documents = google_drive_loader.load()

문서를 임베딩으로 변환

이제 이러한 문서를 임베딩으로 변환하고 Chroma와 같은 벡터 데이터베이스에 저장할 수 있습니다
from langchain.chains import RetrievalQAWithSourcesChain
from langchain_chroma import Chroma
from langchain_openai import OpenAI, OpenAIEmbeddings
from langchain_text_splitters import CharacterTextSplitter
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)

embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_documents(texts, embeddings)
chain = RetrievalQAWithSourcesChain.from_chain_type(
    OpenAI(temperature=0), chain_type="stuff", retriever=docsearch.as_retriever()
)
chain({"question": "what is psychic?"}, return_only_outputs=True)

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I