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

DOC: <Issue related to /v0.2/docs/integrations/vectorstores/typesense> #6105

Closed
2 tasks done
madforce opened this issue Jul 17, 2024 · 1 comment · Fixed by #6117
Closed
2 tasks done

DOC: <Issue related to /v0.2/docs/integrations/vectorstores/typesense> #6105

madforce opened this issue Jul 17, 2024 · 1 comment · Fixed by #6117
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder

Comments

@madforce
Copy link

Checklist

  • I added a very descriptive title to this issue.
  • I included a link to the documentation page I am referring to (if applicable).

Issue with current documentation:

in 0.2 typsense has been moved from langchain/vectorstores/typesense to @lanchain/community/vectorstores/typesense

https://js.langchain.com/v0.2/docs/integrations/vectorstores/typesense

image

Idea or request for content:

No response

@dosubot dosubot bot added the auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder label Jul 17, 2024
Copy link

dosubot bot commented Jul 17, 2024

Hey @madforce! I'm here to help you with any bugs, questions, or contributions you might have. Let's work together to resolve this!

The documentation for integrating Typesense with a vector store in version 0.2 has been updated to reflect the new import path for Typesense. The correct import path is now @langchain/community/vectorstores/typesense. Here is the updated code snippet:

import {
  Typesense,
  TypesenseConfig,
} from "@langchain/community/vectorstores/typesense";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Client } from "typesense";
import { Document } from "@langchain/core/documents";

const vectorTypesenseClient = new Client({
  nodes: [
    {
      // Ideally should come from your .env file
      host: "...",
      port: 123,
      protocol: "https",
    },
  ],
  // Ideally should come from your .env file
  apiKey: "...",
  numRetries: 3,
  connectionTimeoutSeconds: 60,
});

const typesenseVectorStoreConfig = {
  // Typesense client
  typesenseClient: vectorTypesenseClient,
  // Name of the collection to store the vectors in
  schemaName: "your_schema_name",
  // Optional column names to be used in Typesense
  columnNames: {
    vector: "vec", // Default name for the vector column
    pageContent: "text", // Default name for the text column
    metadataColumnNames: ["foo", "bar", "baz"], // Metadata columns
  },
  // Optional search parameters to be passed to Typesense when searching
  searchParams: {
    q: "*",
    filter_by: "foo:[fooo]",
    query_by: "",
  },
  // Custom import function
  import: async (data, collectionName) => {
    await vectorTypesenseClient
      .collections(collectionName)
      .documents()
      .import(data, { action: "emplace", dirty_values: "drop" });
  },
} satisfies TypesenseConfig;

/**
 * Creates a Typesense vector store from a list of documents.
 * Will update documents if there is a document with the same id, at least with the default import function.
 * @param documents list of documents to create the vector store from
 * @returns Typesense vector store
 */
const createVectorStoreWithTypesense = async (documents: Document[] = []) =>
  Typesense.fromDocuments(
    documents,
    new OpenAIEmbeddings(),
    typesenseVectorStoreConfig
  );

/**
 * Returns a Typesense vector store from an existing index.
 * @returns Typesense vector store
 */
const getVectorStoreWithTypesense = async () =>
  new Typesense(new OpenAIEmbeddings(), typesenseVectorStoreConfig);

// Do a similarity search
const vectorStore = await getVectorStoreWithTypesense();
const documents = await vectorStore.similaritySearch("hello world");

// Add filters based on metadata with the search parameters of Typesense
vectorStore.similaritySearch("Rowling", undefined, {
  filter_by: "author:!=JK Rowling",
});

// Delete a document
vectorStore.deleteDocuments(["document_id_1", "document_id_2"]);

For more details, you can refer to the updated documentation here [1][2].

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant