Hier ist meine einfache, abgespeckte Funktion.
Code: Select all
from langchain_weaviate import WeaviateVectorStore
from langchain.schema import Document
from langchain_openai import OpenAIEmbeddings
def upload_chunks_to_weaviate(client, documents, collection_name):
embedder = OpenAIEmbeddings()
vectorstore = WeaviateVectorStore(
client=client,
index_name=collection_name,
text_key="text",
embedding=embedder,
)
doc = Document(page_content="hello world from LangChain + Weaviate")
vectorstore.add_documents([doc])
print(f"Uploaded 1 document to '{collection_name}'")
Code: Select all
if __name__ == "__main__":
client = weaviate.connect_to_local(
skip_init_checks=True,
additional_config=AdditionalConfig(trust_env=True,
timeout=Timeout(init=30, query=60, insert=120) # Values in seconds
))
# Load code from repo
data = loader.read_file('repo_data/example.dart')
# Chunking strategy: "ast", "lines", or "tokens"
strategy = "ast"
kwargs = {}
if strategy == "lines":
kwargs["n_lines"] = 20
elif strategy == "tokens":
kwargs["max_tokens"] = 200
# Chunk the code
chunks = chunk_code(data, strategy=strategy, **kwargs)
upload.upload_chunks_to_weaviate(
client=client,
documents=chunks,
collection_name="RepoChunk",
)
client.close()
Ich verwende LangChain 0.3.27, langchain-weaviate 0.0.5.
Mobile version